Skip to content

subnet/etcd: unify the two subnet watch loops - #2539

Merged
thomasferrandiz merged 2 commits into
flannel-io:masterfrom
mirendev:phinze/unify-subnet-watch-loops
Aug 28, 2026
Merged

thomasferrandiz merged 2 commits into
flannel-io:masterfrom
mirendev:phinze/unify-subnet-watch-loops

Conversation

@phinze

@phinze phinze commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #2524. watchSubnets and watchSubnet had 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. watchSubnet also 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/etcd suite 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/subnet/etcd/registry.go Resolved
@phinze
phinze force-pushed the phinze/unify-subnet-watch-loops branch from c575d8e to d440f1f Compare August 14, 2026 14:33
@phinze

phinze commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor Author

(Looks like those lint failures are on main - two copies of kindCluster.deletePod landed. I'll keep an eye on main lint going green and rebase once I see that.)

phinze added 2 commits August 27, 2026 10:28
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
phinze force-pushed the phinze/unify-subnet-watch-loops branch from d440f1f to 95e4ad4 Compare August 27, 2026 15:28
@thomasferrandiz
thomasferrandiz merged commit 888e930 into flannel-io:master Aug 28, 2026
11 checks passed
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.

3 participants