fix(GODT-2628): Attempt to fix closed channel panic on logout

It should not be possible to reach this state on purpose. But due to
scheduling and synchronization variances, it is possible in theory that
a UserDeathEvent can occur at the same time as the bridge is closing,
causing a call to `User.Close()` to be executed 2 times.

To avoid this in the future we just clear the map after all the channels
have been closed.
This commit is contained in:
Leander Beernaert
2023-05-17 13:10:28 +02:00
parent 40dc17aea5
commit 35f0e081a5
2 changed files with 3 additions and 1 deletions

View File

@ -586,6 +586,8 @@ func (user *User) Close() {
for _, updateCh := range xslices.Unique(maps.Values(user.updateCh)) {
updateCh.CloseAndDiscardQueued()
}
user.updateCh = make(map[string]*async.QueuedChannel[imap.Update])
}, user.updateChLock)
// Close the user's notify channel.