Skip to content

fix(xds): a restarted agent's proxy hears drain marks within 1 s of the agent serving, without dropping its quic: twins; cross-replica drain marks skip the write-behind tick (#1103) - #1118

Merged
bpalermo merged 5 commits into
mainfrom
fix/1103-drain-propagation
Oct 1, 2026

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Refs #1103

Finding: the source proxies had no ADS stream

The drain mark propagates quickly. In both 2026-10-01 TRIPLE instances the source node agent was restarting at the time, so the source proxy had no ADS stream to its agent and kept routing on stale config. The issue said "the same happens with the source agent up". That does not hold for these two: both source agents were mid-restart. Read-only VictoriaLogs, agent/registrar/proxy streams:

step w05 pod jcfxj (10.244.2.115), source w02 w02 pod zv6zw (10.244.4.46), source w04
destination agent marks DRAINING 05:41:20.142 05:41:36.421
registrar receiving replica (n47nr) applies it and broadcasts 05:41:20.142 (same path)
peer replica (sq2cc) etcd watch → sync detected changes 05:41:20.286 (+0.14 s) n/a
source agent old pod gone ~05:41:08; new one started 05:41:15.4, xDS socket open 05:41:20.506 old one shut down 05:41:24.45; new one started 05:41:33.16, xDS socket open 05:41:39.933 (registry wait 3.5 s)
source proxy also rolling (cross-pod hot restart; child forked 05:41:17.74, child CDS 05:41:22.51). Traffic still on the parent epoch. ADS reconnect at 05:41:48.34: 8.4 s after the socket opened, 24 s with no stream
requests to the drained endpoint 05:41:23.92, 24.04 05:41:39.78–39.97
destination pod-boundary steps pool-close 05:41:22.15, CNI DEL 05:41:24.24 pool-close 05:41:38.46, CNI DEL 05:41:40.67

The answers to the questions in the issue:

  • Not polling. The receiving replica applies the mark and broadcasts immediately. The peer replica follows through its etcd watch (200 ms debounce); that took 0.14 s here.
  • Agent snapshot cost (agent: one snapshot build costs 200–870 ms under the cache mutex on a 200m-CPU agent (93% is go-control-plane version-map hashing) — it blocks the ADS stream and still fails a first-use burst if a single build is slow #1105) was not the term. The w02 source agent published snapshots at 21.21, 21.70 and 21.81 that already reflected the mark.
  • Stale persisted endpoints are not the issue either. PreListen holds the socket until the registry load succeeds. The 3.5 s wait on w04 is that hold, and the snapshot it served carried the mark.
  • Envoy and DRAINING. An EDS DRAINING host is excluded from new selections at the pinned Envoy: upstream_impl.cc:699-719 (setEdsHealthFlag sets EDS_STATUS_DRAINING), and upstream_impl.cc:1878-1882 (excludeBasedOnHealthFlag puts it in the excluded set). healthy_panic_threshold: 0 means panic routing never re-selects it. Nothing ever selects it once the update is applied, so the update arriving is the whole problem.
  • Where the time went: the source proxy was blind. Envoy's xDS reconnect backoff is fully jittered exponential with a 500 ms base and a 30 s cap (xds_manager_impl.cc:202-205 RetryInitialDelayMs/RetryMaxDelayMs; backoff_strategy.cc:13-19 returns random() % interval and doubles the interval). The longer the agent was down, the longer the proxy waits after the agent comes back.

Fix (three parts, ship together)

  1. Proxy bootstrap. ads_config.grpc_services[0].envoy_grpc.retry_policy.retry_back_off {base_interval: 0.1s, max_interval: 1s} (charts/aether/templates/agent-proxy-configmap.yaml). The proxy now reconnects within 1 s of the agent's socket opening, however long the agent was away. Each failed attempt is a connect() to a local unix socket that does not exist yet.
  2. Agent: open the xDS socket only on a complete snapshot. This was found while proving part 1. With fast reconnects, a restarted agent's first snapshot predates the SPIRE bridge's re-delivery of the pods' certificates. The QUIC twins: first use after an agent+proxy restart takes >5 s to publish — Envoy's on-demand fetch times out and 428 requests fail 503 NC cluster_not_found (rev248 phase C, 15:44:51Z) #1049 gate therefore leaves every quic: twin out of it, and the reconnecting proxy is told to remove the twins it holds (cds: ... 0 added/updated, 1 removed, remove cluster 'quic:quic-a...@aether-test/client-a'). Routes keep selecting the twin until the certificate's snapshot re-adds it.
    • With part 1 and main's agent on kind: this happened on 8 of 18 restarts, lasting 1–9.6 s each, and one restart cost 56 × 503.
    • With main's slow backoff it was mostly hidden (1 of 13), because the proxy usually reconnected after the certificates had arrived.
    • Fix: PreListen now waits, bounded at 5 s, until SnapshotCache.AwaitingClientCertificates() == 0. This is node agent only (identity gate set).
    • On talos-main it costs nothing: in all five TRIPLE agents of 2026-10-01 the certificates arrived 0.3–2.6 s before the registry load finished.
  3. Registrar: write-behind flushes on enqueue. Before this, a fresh intent waited up to one 500 ms wbTick before the external registry (and therefore the peer replica's watch) saw it. This was the cross-replica steady-state term: on kind, mark → last request was 0.5–0.9 s cross-replica against 0.2 s same-replica. The ticker still drives retries and backoff.

Docs: new runbook section "A source keeps picking an endpoint seconds after its drain mark (#1103)".

Evidence

Unit tests (seen red, then green):

  • //test/envoy_validate TestNodeProxyADSReconnectBackoffIsBounded reads the chart's retry_back_off, asserts the cap is ≤ 1 s, and runs envoy --mode validate on a bootstrap carrying it.
    • Red against main's configmap: ads_config carries no retry_policy.retry_back_off ... stays blind up to 30 s.
    • Also pinned in the packaged chart: //charts/aether:aether_proxy_bootstrap_ads_reconnect_backoff_test.
  • //agent/internal/xds/server TestPreListen_WaitsForLocalClientCertificates, plus bounded / no-gate / shutdown cases, run against the real cache: a local pod whose SVID has not arrived yet.
    • Red with the wait disabled: PreListen returned ... while the snapshot still held 1 local identity out of east-west QUIC.
  • //registrar/internal/server TestWriteBehindFlushesANewIntentWithoutWaitingForTheTick.
    • Red with the kick disabled: Condition never satisfied ... well inside one wbTick (500ms).

kind red → green. The new harness is e2e/drain-propagation.sh (cluster aether-1103):

  • Bring-up: the EWQ_WORKER=1 shape, on the etcd registry backend as talos runs it, with 2 registrar replicas.
  • Workload: quic-a ×2 on the worker with a 15 s preStop sleep, so a deleted replica's app logs every request a source still sends it.
  • Load: 4 GET loops from client-a on the control plane.
  • Measured gap = last request at the victim's app − the destination agent's drain mark.
  • Leg S: delete a replica.
  • Leg R: delete the source agent pod, then 2 s later delete the replica.
  • Arms are switched in place: bootstrap main|fix rewrites the live ConfigMap and waits for the hot restart to load it (read back from the admin config dump); swap-agent; registrar image.
arm (6 runs/leg) S gap (s) R: agent serving → proxy reconnected (s) R gap (s) R: CDS removals after reconnect R non-200
main (bootstrap + agent + registrar) 0.09–0.26 0.17, 0.90, 2.98, 5.29, 5.95, 12.75 (second round: 0.31–4.74) 4.0–15.0 (preStop cap) 1 of 13 2
bootstrap fix only, main agent 0.19–0.25 0.06–0.78 3.2–11.1 8 of 18 (1–9.6 s each) 56 in one run; 4, 3, 4 in three others
all three (this PR) 0.15–0.23 0.40–0.84 3.2–13.7 0 of 12 0

The R gate (DRP_EXPECT=green) asserts every reconnect is ≤ 1.5 s and that no CDS removal follows a reconnect. The S gate asserts every gap is ≤ 1 s.

Two more observations:

  • On two runs right after a component swap, steady state read 0.5–0.9 s; one of those runs had a single 3.0 s straggler request. That is the cross-replica write-behind term (part 3). The final run is 0.15–0.23 s. The harness cannot tell which registrar replica each agent was on, so the cross-replica improvement is proven by the unit test, not isolated on kind.
  • The R gap stays 3–14 s after the fix: it is dominated by the source agent's own outage (pod delete → new agent serving xDS: 6–16 s on kind, 15.5 s on talos w04). This PR removes the reconnect tail on top of it, which was 0.2–12.8 s on kind and 8.4 s on talos. For the w04 case alone, the requests at 39.78–39.97 were sent before or at the moment the agent's socket opened (39.93), so even a perfect reconnect would not have saved them. Part 1 would have saved the w02-type case (agent serving 3.4 s before the requests).

Checks:

  • bazel test for //agent/..., //registrar/internal/server:all, //agent/internal/xds/cache/..., //test/envoy_validate:all, //charts/aether:all: pass.
  • --config=race on //agent/internal/xds/server:all, //agent/internal/xds/cache:all, //registrar/internal/server:all, //test/envoy_validate:all: pass.
  • make gazelle, make format, and bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...: clean.
  • Chart bumped to 2.1.1 (main is 2.1.0).

What remains on #1103 (why this is Refs)

Tonight's soak

Safe to ride, with the soak watching agent restarts. Parts 2 and 3 are small and covered by tests; part 2 costs 0 on talos per the 2026-10-01 timings. The bootstrap change hot-restarts every proxy once on deploy (the supervisor's ConfigMap watch), as any chart bootstrap change does. If the soak shows remove cluster 'quic:...' right after an agent restart (proxy debug) or local workloads' client certificates not delivered in time (agent WARN), that is the part 2 bound being hit.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 5 commits October 1, 2026 14:19
…started agent's drain marks reach it promptly (#1103)

While the ADS stream to the node agent is down the proxy routes on its
last config, so a destination marked DRAINING in the meantime is still
selected. Envoy's xDS default (fully jittered, 500 ms base, 30 s cap)
left main-worker-04's proxy reconnecting 8.4 s after its restarted agent
was serving again on 2026-10-01; it sent three requests to a pod drained
3.4 s earlier. retry_back_off {0.1s, 1s} bounds that tail to < 1 s.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
… certificates are in the snapshot (#1103)

A restarted agent served its first snapshot before the SPIRE bridge had
re-delivered the pods' certificates, so the #1049 gate left every quic:
twin out of it. A proxy reconnecting to that snapshot is told to remove
the twins it holds and routes into the gap until the certificate's
snapshot re-adds them: on kind, 1-9.6 s of cluster_not_found per restart,
56 x 503 in one. Envoy's 30 s reconnect backoff hid it most of the time;
the 1 s cap makes it the common case. PreListen now waits (bounded, 5 s)
for the snapshot to carry every local certificate.

Also: e2e/drain-propagation.sh (kind proof) and the runbook entry.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…he next write-behind tick (#1103)

A peer registrar replica sees an endpoint change only once the external
registry holds it. Waiting for the 500 ms tick put up to half a second
into every cross-replica drain mark (0.5-0.9 s mark -> last request on
kind, against 0.2 s when both agents share a replica). Enqueue now kicks
the flush loop; the ticker keeps driving retries.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 5b7cc7d into main Oct 1, 2026
24 checks passed
@bpalermo
bpalermo deleted the fix/1103-drain-propagation branch October 1, 2026 19:00
bpalermo added a commit that referenced this pull request Oct 2, 2026
…t serves its node proxy (#1123) (#1135)

* fix(agent): an agent restart stops waiting out retry ladders before it serves its node proxy (#1123)

The node proxy has no ADS stream from the old agent's exit until the new one
serves xDS. Measured on kind (e2e/agent-restart-gap.sh, proxy-side
control_plane.connected_state, 2 nodes, etcd backend): median 12.0 s / p99
17.9 s on main (n=16), median 5.5 s / p99 8.8 s on this branch (n=20).

Startup, after the agent's own SVID, drops from ~6 s to ~0.1 s:
- The registrar client's post-identity reconnect waits for the ClientConn to
  be READY instead of sleeping a whole 1 s backoff after the wake's first
  retry lost the redial race (the steady ~1.05 s on every talos node).
- The SPIRE bridge's pod subscriptions retry the moment the agent's own SVID
  is served (with the broker connection's backoff reset) instead of on their
  1 s+ doubling ladder; on main the client-certificate first-serve gate of
  #1118 hit its 5 s bound in 7 of 16 kind restarts.
- Every Workload API source retries 200 ms / 400 ms / then every 500 ms
  instead of go-spiffe's linear whole-second ladder.
- PreListen builds the local listeners from storage during the identity hold
  (the socket still opens only after identity, capture projection, registry
  load and client certificates); the #877 TCP-floor WARN gets a 1 min startup
  grace with SPIRE on so this does not log on every restart.

Pod replacement:
- agent and cni-install images default to IfNotPresent (digest-pinned; the
  kubelet counted 1.44 s of image checks on one talos restart).
- cni-install leaves an identical plugin binary, conflist and durable entry
  alone instead of rewriting and fsyncing them on every pod start.
- Readiness probed every 2 s from the start (Ready ~1 s after container
  start instead of ~10 s), failureThreshold 15 keeps 30 s to NotReady.

The remaining terms (pod replacement 2.8-3.4 s on kind, the SPIRE first SVID
1-5 s on kind / 0.15-2 s on talos) are not the agent's to remove; proposal 041
designs the surge roll with a standby agent that removes both.

Chart 2.2.0 -> 2.2.1.

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

* fix(spire): drop the broker ClientConn backoff reset that races grpc-go's subchannel map; redial on a 250 ms cap instead (#1123)

grpc-go's ClientConn.ResetConnectBackoff copies the map reference under cc.mu
and iterates it after unlocking, so it races newAddrConnLocked writing the
same map (the race job on #1135: TestBridgeSurvivesSubscribeFailures, 12 of
20 local runs). The broker connection is node-local; it now redials on a
50 ms base / 250 ms cap backoff, which bounds how long WaitReady takes after
the agent's SVID lands without touching the ClientConn's internals.

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

* chore(chart): aether 2.2.2 (above main's 2.2.1) (#1123)

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

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
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