fix(GODT-2590): Fix send on closed channel

Ensure periodic user tasks are terminated before the other user
services. The panic triggered due to the fact that the telemetry service
was shutdown before this periodic task.
This commit is contained in:
Leander Beernaert 2023-09-26 09:20:01 +02:00
parent cf3abaa96f
commit c0992e8801
1 changed files with 5 additions and 5 deletions

View File

@ -589,6 +589,8 @@ func (user *User) Logout(ctx context.Context, withAPI bool) error {
return fmt.Errorf("failed to remove user from imap server: %w", err)
}
user.tasks.CancelAndWait()
// Stop Services
user.serviceGroup.CancelAndWait()
@ -598,8 +600,6 @@ func (user *User) Logout(ctx context.Context, withAPI bool) error {
// Close imap service.
user.imapService.Close()
user.tasks.CancelAndWait()
if withAPI {
user.log.Debug("Logging out from API")
@ -621,6 +621,9 @@ func (user *User) Logout(ctx context.Context, withAPI bool) error {
func (user *User) Close() {
user.log.Info("Closing user")
// Stop any ongoing background tasks.
user.tasks.CancelAndWait()
// Stop Services
user.serviceGroup.CancelAndWait()
@ -630,9 +633,6 @@ func (user *User) Close() {
// Close imap service.
user.imapService.Close()
// Stop any ongoing background tasks.
user.tasks.CancelAndWait()
// Close the user's API client.
user.client.Close()