feat(GODT-2442): handle bad event resync resolution.

This commit is contained in:
Jakub
2023-03-03 17:20:49 +01:00
parent 53c2cbcaee
commit 8c0bb22de3
3 changed files with 54 additions and 7 deletions

View File

@ -86,12 +86,22 @@ func (user *User) handleRefreshEvent(ctx context.Context, refresh proton.Refresh
l.WithError(err).Error("Failed to report refresh to sentry")
}
// Cancel the event stream once this refresh is done.
defer user.pollAbort.Abort()
return user.SyncEvent(ctx)
}
// Resync after the refresh.
func (user *User) SyncEvent(ctx context.Context) error {
// Cancel the event stream
user.pollAbort.Abort() // ??? There was a defer here. But I think it's best to do this immediately, there is no reason to continue with polls while having re-sync.
// Re-sync messages after the user, address and label refresh.
defer user.goSync()
// stop IMAP and SMTP
if err := user.vault.SetEventID(""); err != nil {
return fmt.Errorf("failed to clean latest event ID: %w", err)
}
return safe.LockRet(func() error {
// Fetch latest user info.
apiUser, err := user.client.GetUser(ctx)