fix concurrent map writes (#2079)

Co-authored-by: wero <wero@werodeMacBook-Pro.local>
This commit is contained in:
givemeafish
2022-07-01 23:07:25 +08:00
committed by GitHub
parent f2cef2b963
commit 6a4885ba64

View File

@@ -191,9 +191,11 @@ func (c *cluster) handleWatchEvents(key string, events []*clientv3.Event) {
})
}
case clientv3.EventTypeDelete:
c.lock.Lock()
if vals, ok := c.values[key]; ok {
delete(vals, string(ev.Kv.Key))
}
c.lock.Unlock()
for _, l := range listeners {
l.OnDelete(KV{
Key: string(ev.Kv.Key),