From 6a4885ba64aa55efe376d94048c5e3225ffb817b Mon Sep 17 00:00:00 2001 From: givemeafish <981819494@qq.com> Date: Fri, 1 Jul 2022 23:07:25 +0800 Subject: [PATCH] fix concurrent map writes (#2079) Co-authored-by: wero --- core/discov/internal/registry.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/discov/internal/registry.go b/core/discov/internal/registry.go index 77949e2e..ad37fda3 100644 --- a/core/discov/internal/registry.go +++ b/core/discov/internal/registry.go @@ -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),