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:
James Houlahan
2022-10-25 12:53:12 +02:00
parent dabc9717d1
commit 14fbdb5e04
2 changed files with 11 additions and 5 deletions

View File

@ -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()