forked from Silverfish/proton-bridge
Other: Fix race condition when changing address mode
When changing address mode, we would close all a user's update channels and create them from scratch. This involved setting user.updateCh to a new value. However, it was possible for other goroutines to read from user.updateCh during this time. I replaced it with a call to user.updateCh.Clear(), which is threadsafe.
This commit is contained in:
@ -262,6 +262,14 @@ func (m *Map[Key, Val]) ValuesErr(fn func(vals []Val) error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Map[Key, Val]) Clear() {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
|
||||
m.data = make(map[Key]Val)
|
||||
m.order = nil
|
||||
}
|
||||
|
||||
func (m *Map[Key, Val]) MapErr(fn func(map[Key]Val) error) error {
|
||||
m.lock.RLock()
|
||||
defer m.lock.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user