fix: resolve data race in service discovery map access (#5408)

This commit is contained in:
Kevin Wan
2026-02-06 23:16:05 +08:00
committed by GitHub
parent bdddf1f30c
commit b139a82c2e
2 changed files with 69 additions and 3 deletions

View File

@@ -433,16 +433,16 @@ func (c *cluster) setupWatch(cli EtcdClient, key watchKey, rev int64) (context.C
}
ctx, cancel := context.WithCancel(cli.Ctx())
c.lock.Lock()
if watcher, ok := c.watchers[key]; ok {
watcher.cancel = cancel
} else {
val := newWatchValue()
val.cancel = cancel
c.lock.Lock()
c.watchers[key] = val
c.lock.Unlock()
}
c.lock.Unlock()
rch = cli.Watch(clientv3.WithRequireLeader(ctx), wkey, ops...)