Skip to content

fix(discov): avoid duplicate watch events and monitors,duplicate addKv#5576

Open
YangXiaowu wants to merge 2 commits into
zeromicro:masterfrom
YangXiaowu:fix/discov-watch-duplicate-events
Open

fix(discov): avoid duplicate watch events and monitors,duplicate addKv#5576
YangXiaowu wants to merge 2 commits into
zeromicro:masterfrom
YangXiaowu:fix/discov-watch-duplicate-events

Conversation

@YangXiaowu
Copy link
Copy Markdown

What problem does this PR solve?

This PR fixes two issues in etcd discovery watchers:

  1. Duplicate etcd PUT events for the same key/value caused subscribers to
    repeatedly append the same key in the local container, which could lead to
    unbounded memory growth.
  2. Multiple monitors for the same endpoints/key could start duplicate etcd
    watch goroutines instead of reusing the existing watcher.

What is changed?

  • Ignore duplicate PUT events when the key already has the same value.
  • When a key changes to a different value, notify listeners with
    OnDelete(old) before OnAdd(new).
  • Use the previously stored value for delete notifications when available.
  • Prevent repeated Monitor calls for the same watch key from starting
    duplicate watch streams.
  • Add regression tests for duplicate PUT handling and duplicate monitor
    handling.

Tests

go test ./core/discov/...
go test ./zrpc/resolver/...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant