Skip to content

fix(capture): a mesh-Service re-projection no longer strips the declared-port TCP chains, and the first serve waits for the projection (#1094) - #1099

Merged
bpalermo merged 1 commit into
mainfrom
fix/1094-capture-chains-after-agent-restart
Oct 1, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/1094-capture-chains-after-agent-restart

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Closes #1094

Root cause

It was not an incomplete first snapshot. It was a mid-life flap that an agent restart makes dense.

SetCaptureTCPServices (agent/internal/xds/cache/capture.go:282, on main) built each captureTCPEntry from the capture reconciler's input only: name, VIP and primaryIsTCP. It dropped primaryPort and tcpPorts. Only refreshCaptureTCPPorts (capture.go:1323, called from a registry load at cluster.go:324) fills those two fields in. As a result:

  1. An unchanged re-projection compared as a change in equalTCPEntries, because the derived fields went to zero.
  2. Every capture listener was rebuilt without its destination_port chains. That removes the cap_tcp_<svc>_<primary> chain and every non-primary per-port chain. The :18082 and anyport chains stay.
  3. Any snapshot pushed before the next registry load served a declared port from cap_tcp_anyport_*. After proposal 037 Phase 4 it would be served by nothing. The in-place LDS update also drains the connections on the removed chains.

The capture reconciler runs once per mesh Service when its informer first lists them. After a restart those runs interleave with the first registry loads. From the w03 agent log (VictoriaLogs, aether-agent-q6rxl):

time (Z) event
05:41:53.879 xDS gRPC server starts (first serve)
05:41:54.950 loaded clusters from registry (ports derived)
05:41:55.054 projected mesh-Service authorities (ports wiped, listeners rebuilt)
05:41:55.081 setting snapshot …11 (the tail of that load, now chainless)
05:41:55.436 tcp-echo 10.96.11.228:9000 served by cap_tcp_anyport_tcp:tcp-echo…
05:41:55.979 next loaded clusters restores the chains, snapshot .12

Fix

  • Primary (cache.go, capture.go). The cache keeps the last derivation (captureDerivedTCPPorts / captureDerivedPrimaryPorts) and SetCaptureTCPServices applies it.
    • The two halves of an entry now compose in either order.
    • An unchanged re-projection is no longer a change, so no listener is rebuilt.
  • Defence for the first serve (server.go, root.go, capture/reconciler.go). Nothing ordered the socket opening after the reconciler's first projection; on talos the registry wait happened to outlast it.
    • The cache exposes CaptureProjected().
    • PreListen waits on it before the registry load whose snapshot the socket opens on. The wait is bounded at 10 s, returns nil on shutdown, and logs a WARN on timeout.
    • The capture controller gets one synthetic event (source.Channel), so a mesh with no Services still projects and does not sit out the bound. The event goes through the controller's own workqueue so projections stay serialized.
    • A missing optional CRD cannot block: this reconciler watches core Services only.

Evidence

Unit, red on main then green: TestCaptureReprojectionKeepsDeclaredPortChains (cache).

  • On main, 3 of 4 subtests fail:
    • re-projection after a load (the talos order)
    • load before the first projection
    • a new Service joining
  • Each failure shows a missing _9000 / _9001 chain. The identical-re-projection subtest also fails its byte-equality check.
  • TestPreListen_HoldsUntilCaptureProjection / _CaptureGateIsBounded / _CaptureGateEndsOnShutdown cover the gate (server).
  • TestInitialProjection_OneEventThatProjectsAnEmptyMesh covers the synthetic event (capture).

kind, red then green (e2e/l4routes.sh up, cluster aether-1094, single node). Each run: 32 bursts of 5 no-op mesh-Service annotation updates, with 4 parallel dial loops to l4-a…:9000 (TCP-primary, declared port). Counters were read from Envoy admin.

agent dials cap_tcp_anyport_tcp:l4-a… cap_tcp_…l4-a…_9000 listener_manager.listener_modified
main (75caf0f) 1292 +138 +1154 +556
this branch 1284 +0 +1284 +0
  • Single, unbursted updates on main did not leak to anyport in kind: the refresher's own reload restores the ports before it publishes. They still caused 72 listener modifications per 10 no-op updates. Bursts reproduce the talos race: an update lands while a reload is in flight.
  • An agent pod restart under the dial loop gave anyport +0 on both builds in kind (12 mesh Services, too few to hit the window). It caused +12 listener_modified on both builds, the same count, so that is a restart artifact unrelated to this fix.
  • On the branch the agent logged mesh-Service projection received … waited=109ms at startup, so the gate did hold the first serve in kind.
  • Full ./e2e/l4routes.sh verify on the branch passes: TCPRoute, TLSRoute and UDPRoute legs.

Checks run:

  • bazel test //agent/... (non-integration): 43/43 pass.
  • --config=race on xds/cache, l4route, xds/server, capture: pass.
  • make gazelle, make format, and bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...: clean.

Open risks / not in scope

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…red-port TCP chains, and the first serve waits for the projection (#1094)

SetCaptureTCPServices rebuilt its entries from the capture reconciler's input
alone (name, VIP, primary class) and dropped the endpoint-derived primaryPort
and tcpPorts that only refreshCaptureTCPPorts (a registry load) fills in.
equalTCPEntries then saw a change, so EVERY mesh-Service event rebuilt every
capture listener without its destination_port chains until the next registry
load. A snapshot pushed inside that window served connections to a declared
port from the any-port shim (past proposal 037 Phase 4: from nothing), and
the in-place update drained the connections on the removed chains.

An agent restart interleaves one reconcile per mesh Service with its first
registry loads, which is how talos hit it: on main-worker-03 a registry load
derived the ports (05:41:54.950), the reconciler re-projected (05:41:55.054),
snapshot .11 went out (05:41:55.081) and served tcp-echo:9000 from
cap_tcp_anyport_* (05:41:55.436), and the next load put the chain back
(05:41:55.979). The xDS socket had opened at 05:41:53.879, so this was a
mid-life flap, not an incomplete first snapshot.

Fix: the cache keeps the last derivation and SetCaptureTCPServices applies
it, so the two halves of an entry compose in either order and an unchanged
re-projection is not a change.

Also close the first-serve gap the investigation exposed: nothing ordered the
xDS socket opening after the reconciler's first projection (on talos the
registry wait happened to outlast it). The cache now exposes
CaptureProjected(), PreListen waits on it (bounded, 10 s) before the registry
load whose snapshot the socket opens on, and the capture controller gets one
synthetic event so a mesh with no Services still projects.

kind (l4routes, single node), 32 bursts of 5 no-op mesh-Service updates
under 4 dial loops to l4-a:9000:
  main:   cap_tcp_anyport +138 / 1292 dials, listener_modified +556
  branch: cap_tcp_anyport +0   / 1284 dials, listener_modified +0

Closes #1094

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
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.

capture: a connection to a DECLARED port landed on the anyport floor chain 12 s after an agent restart (blocks dropping anyport, proposal 037 Phase 4)

1 participant