fix(discov): prevent unbounded memory growth on duplicate etcd PUT events (#5580)

This commit is contained in:
Kevin Wan
2026-05-16 12:35:05 +08:00
committed by GitHub
parent 4ad4fd43b7
commit 7b5e7b1c26
4 changed files with 148 additions and 8 deletions

View File

@@ -141,12 +141,23 @@ func (c *container) addKv(key, value string) ([]string, bool) {
c.lock.Lock()
defer c.lock.Unlock()
oldVal, alreadyMapped := c.mapping[key]
if alreadyMapped && oldVal == value {
// duplicate PUT with same key+value, nothing to do
return nil, false
}
c.dirty.Set(true)
if alreadyMapped {
// key moved to a new value; remove stale entry to prevent leak
c.doRemoveKey(key)
}
keys := c.values[value]
previous := append([]string(nil), keys...)
early := len(keys) > 0
if c.exclusive && early {
for _, each := range keys {
for _, each := range previous {
c.doRemoveKey(each)
}
}