From 0c8d4e8dd80d71d6e8d2143f9be9489dc6c825b5 Mon Sep 17 00:00:00 2001 From: Leander Beernaert Date: Thu, 2 Feb 2023 11:19:32 +0100 Subject: [PATCH] fix(GODT-2326): Only run sync after addIMAPUser() There is concurrency bug due to competing sync calls that can occur when we clear the sync status in the Vault. Running sync at the end of addIMAPUser() avoids the problem. This patch also remove the execution of a sync task for `user.ClearSyncStatus()` --- internal/bridge/imap.go | 1 + internal/user/user.go | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/bridge/imap.go b/internal/bridge/imap.go index a9f411e0..8c2dcbdb 100644 --- a/internal/bridge/imap.go +++ b/internal/bridge/imap.go @@ -172,6 +172,7 @@ func (bridge *Bridge) addIMAPUser(ctx context.Context, user *user.User) error { } } + user.TriggerSync() return nil } diff --git a/internal/user/user.go b/internal/user/user.go index abdbadb3..d7423827 100644 --- a/internal/user/user.go +++ b/internal/user/user.go @@ -234,12 +234,13 @@ func New( }) }) - // Trigger an initial sync (if necessary). - user.goSync() - return user, nil } +func (user *User) TriggerSync() { + user.goSync() +} + // ID returns the user's ID. func (user *User) ID() string { return safe.RLockRet(func() string { @@ -482,11 +483,8 @@ func (user *User) GetSyncStatus() vault.SyncStatus { return user.vault.GetSyncStatus() } -// ClearSyncStatus clears the sync status of the user. This triggers a resync. +// ClearSyncStatus clears the sync status of the user. func (user *User) ClearSyncStatus() error { - user.abortable.Abort() - defer user.goSync() - return user.vault.ClearSyncStatus() }