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()`
This commit is contained in:
Leander Beernaert
2023-02-02 11:19:32 +01:00
committed by Jakub
parent b17bdad864
commit 76d732f247
3 changed files with 16 additions and 7 deletions

View File

@ -149,6 +149,7 @@ func (bridge *Bridge) addIMAPUser(ctx context.Context, user *user.User) error {
} }
} }
user.TriggerSync()
return nil return nil
} }

View File

@ -232,12 +232,13 @@ func New(
}) })
}) })
// Trigger an initial sync (if necessary).
user.goSync()
return user, nil return user, nil
} }
func (user *User) TriggerSync() {
user.goSync()
}
// ID returns the user's ID. // ID returns the user's ID.
func (user *User) ID() string { func (user *User) ID() string {
return safe.RLockRet(func() string { return safe.RLockRet(func() string {
@ -475,11 +476,13 @@ func (user *User) OnStatusDown(context.Context) {
user.abortable.Abort() user.abortable.Abort()
} }
// ClearSyncStatus clears the sync status of the user. This triggers a resync. // GetSyncStatus returns the sync status of the user.
func (user *User) ClearSyncStatus() error { func (user *User) GetSyncStatus() vault.SyncStatus {
user.abortable.Abort() return user.vault.GetSyncStatus()
defer user.goSync() }
// ClearSyncStatus clears the sync status of the user.
func (user *User) ClearSyncStatus() error {
return user.vault.ClearSyncStatus() return user.vault.ClearSyncStatus()
} }

View File

@ -197,6 +197,11 @@ func (user *User) RemFailedMessageID(messageID string) error {
}) })
} }
// GetSyncStatus returns the user's sync status.
func (user *User) GetSyncStatus() SyncStatus {
return user.vault.getUser(user.userID).SyncStatus
}
// ClearSyncStatus clears the user's sync status. // ClearSyncStatus clears the user's sync status.
func (user *User) ClearSyncStatus() error { func (user *User) ClearSyncStatus() error {
return user.vault.modUser(user.userID, func(data *UserData) { return user.vault.modUser(user.userID, func(data *UserData) {