Repository navigation
subnet/etcd: unify the two subnet watch loops - #2539
Merged
thomasferrandiz merged 2 commits intoAug 28, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Unifies etcd subnet watch handling to prevent recovery behavior from diverging.
Changes:
- Centralizes reconnect, backoff, cancellation, and compaction recovery.
- Skips malformed watch events and adds cancellation-aware delivery.
- Updates interfaces, callers, mocks, and focused tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
pkg/subnet/etcd/registry.go |
Implements the unified watch driver and event handling. |
pkg/subnet/etcd/registry_test.go |
Tests malformed events and blocked delivery cancellation. |
pkg/subnet/etcd/mock_registry.go |
Updates the mock watch signature. |
pkg/subnet/etcd/local_manager.go |
Updates the watch caller and removes obsolete handling. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
phinze
force-pushed
the
phinze/unify-subnet-watch-loops
branch
from
August 14, 2026 14:33
c575d8e to
d440f1f
Compare
Contributor
Author
|
(Looks like those lint failures are on main - two copies of |
watchSubnets and watchSubnet were near-identical copies of one reconnect loop. That is why the compaction fix landed in the first (flannel-io#2471) months before the second (flannel-io#2524): nothing connected them, so fixing one did not even suggest the other. Both now call a shared runWatch that owns the reconnect loop, backoff, compaction recovery and revision bookkeeping. What genuinely differs stays in a subnetWatch struct: the key, start revision, result channel and resync callback. The two response converters are unified too. Their apparent differences were artifacts of copied code: the parser already sets EnableIPv4, compaction is reported by the watch response rather than event parsing, and cursor-only or empty results misrepresent parse failures as snapshots. The shared converter skips malformed events, while TTL lookup failures retry from the same revision instead of advancing past an event. watchSubnet picks up the resync retry loop watchSubnets already had. Retry waits and result delivery honor context cancellation, so a blocked receiver cannot keep the watch alive. Each per-attempt watch context is also canceled before reconnecting rather than accumulating deferred cleanup for the lifetime of the loop.
watchSubnets took (ctx, chan, since) while watchSubnet took (ctx, since, sn, sn6, chan), so two adjacent functions in the same interface disagreed about where the revision and the channel belong. Both are now (ctx, since, [subnet], chan), which is watchSubnet's existing shape, so only watchSubnets moves. Mechanical: the interface, the mock, one caller in local_manager.go and two in the tests.
phinze
force-pushed
the
phinze/unify-subnet-watch-loops
branch
from
August 27, 2026 15:28
d440f1f to
95e4ad4
Compare
thomasferrandiz
approved these changes
Aug 28, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #2524.
watchSubnetsandwatchSubnethad separate copies of the same long-lived etcd watch. That split is how compaction recovery reached one in #2471 while the identical bug survived in the other until #2524. This puts watch recovery and event handling on one path so fixes cannot drift between them again.Unifying the paths also exposed unsafe legacy failure handling. The plural watch turned a malformed event into an empty or cursor-only
LeaseWatchResult. Downstream treats an eventless result as a snapshot, so a parse failure could look like an empty snapshot and remove every known peer. Malformed events are now logged and skipped, while TTL lookup failures retry from the same revision.watchSubnetalso picks up the existing resync retry behavior, and retry waits and result delivery stop promptly on cancellation.All four compaction regression tests pass, plus focused tests for malformed events, TTL failures, and cancellation with a blocked receiver. The full
pkg/subnet/etcdsuite and its race-enabled run pass; gofmt,go vet, and golangci-lint v2.7.2 are clean. The resync retry failure branch is not directly fault-injection tested.