Skip to content

fix(quic): a twin pair Envoy has subscribed to is never forgotten — dormant while its source or destination is away, republished on return, pruned only when the subscription is gone (#1036) - #1038

Merged
bpalermo merged 6 commits into
mainfrom
fix/1036-dormant-twin-pairs
Sep 28, 2026

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Stacked on #1035. #1035 has not merged yet, so this PR's base is its branch, fix/quic-pairs-no-readmit, and the diff shows only #1036. When #1035 lands, GitHub retargets this PR to main. If that does not happen automatically, retarget it by hand.

Mechanism

Envoy's ODCDS manager keeps one subscription per cluster name for the life of the process. Before this PR, the agent removed a twin the proxy had fetched on demand in two cases:

  • the source ServiceAccount's last pod left the node (pruneQUICPairsLocked, source_left_node);
  • the destination left the allow-list or the dependency set.

When that happens, Envoy drops the cluster and keeps the subscription. Every later on-demand request for the name is already subscribed, skipping inside the proxy and never reaches the agent. So when a pod of that ServiceAccount came back to the node (a Deployment roll does this all the time), its route selected a name Envoy would never ask for again. Every request then 503'd NC at the 2 s on_demand timeout until the proxy restarted. The soak's churn on talos rev245 would hit this.

This is now reproduced live, not only inferred. The forget control below is exactly the #1036 sequence: fetch, prune on source departure, source returns, request.

Fix

The subscription is still open, so the control plane can push the twin again at any time and Envoy takes it without a new request. The agent therefore never forgets a pair Envoy has subscribed to.

The ledger. agent/internal/xds/quicdemand/ledger.go (new) adds Ledger[K], which records which twins the proxy holds an ODCDS subscription for:

  • every name it asked for on first use, including a refused one, because the subscription stays open either way;
  • every name it re-subscribed on a fresh stream.

It lives in quicdemand so the live gate runs the agent's ledger, not a copy of it. That is the same reason #1035 put the classifier there.

Pair lifecycle (cache/quicpairs.go):

  • Leave. A pair loses its source or destination. If the proxy holds its subscription, the pair goes dormant: the twin leaves the snapshot as before, and the prune line reads (source_left_node, dormant). A pair with no subscription behind it is forgotten as before. The proxy drops such a cluster outright, and its next request is ordinary first use.
  • Return. A pod of the ServiceAccount comes back, or the destination is re-listed. The same snapshot republishes the dormant pair's twin and its load assignment (reviveDormantQUICPairsLocked), and logs republished dormant east-west QUIC pairs ….
  • Refused first use. A request with a well-formed name that the agent refuses (for example a source_not_local race) is parked dormant. Only the refused request 503s, not every one after it.
  • Prune. A dormant pair is pruned only when the subscription is gone. RestateQUICSubscriptions runs on every fresh stream's first CDS request, including one that re-subscribes nothing. That request's re-subscribed set is the proxy's full subscription set, so a dormant pair it does not name is pruned. This covers an agent restart against a proxy that no longer holds the subscription, and a proxy generation change: a hot-restart child has no ODCDS subscriptions, and its first request names none. quicdemand.Classification gains Fresh so the observer can tell. The observer's non-fresh re-subscriptions still go through ResumeQUICSubscriptions, which does not touch the rest of the ledger.
  • Persistence. Dormant pairs are stored in the new ObservedUpstreams.dormant_quic_pairs field (field 3; an older agent ignores it) and restored at load. A restored dormant pair whose source is on the node once the pod set is known is republished by the first snapshot after that, before any request. One whose source is still away stays dormant until the fresh stream keeps it or prunes it.
  • The fix(quic): a twin pair is admitted only on real first use — held-only twins are dropped on a fresh stream, live re-subscriptions keep serving, stale persisted pairs are pruned (#1033) #1035 rules are unchanged. Held-only twins admit nothing, re-subscriptions are served, and the fetch-window prune still applies. That prune now also skips a served pair the proxy holds a subscription for, and never sees a dormant pair.

ledger.go documents the ledger's rule.

Gates, each seen red

How red was produced for the unit gates and the live dormant arm: the ledger was made to forget, i.e. #1035's behaviour. Retire always returned false and Park was a no-op. Every new cache and server test failed:

  • TestQUICDormantPairRepublishedWhenSourceReturns: expected [quic:echo…@demo/source-a] actual [] (not dormant, not persisted: "[]" should have 1 item(s)).
  • …WhenDestinationIsRelisted: re-listed: both twins republished with no request, elements differ.
  • …PersistAcrossAgentRestart: "[]" should have 3 item(s), but has 0.
  • …PrunedOnProxyGenerationChange and TestQUICRefusedFirstUseIsParkedDormant failed the same way.
  • server/TestOnDemandObserver_FreshStreamRestatesSubscriptionsForDormantPairs: a subscribed, unservable twin is kept dormant, expected [quic:echo…@demo/away] actual [].
  • The live dormant arms failed with the dormant twin must be republished with no request (issue #1036), condition never satisfied.

The ledger was then restored, and all of these are green.

1. Live, source leaves and returns (//test/mtlspool, TestOnDemandQUICDormantTwinRepublishedWhenSourceReturns; delta ADS, pinned proxy, real HTTP/3 destination that requires the client certificate). Source A fetches its twin on demand (200 … HTTP/3.0 in 26.2ms), A's ServiceAccount leaves (twin removed), and A's ServiceAccount returns.

2. Live, destination delisted and re-listed (…WhenDestinationIsRelisted). Same two arms and the same result: the dormant arm is republished with no request and returns 200/h3, and the forget_control arm 503s at 2.000 s.

Harness note: the live gate waits for Envoy to finish tearing down the removed twin before the "return". It waits until the proxy has released the twin's EDS name and its certificate's SDS name. The reason is a go-control-plane artefact, not the behaviour under test. If the return lands inside the same few milliseconds, the delta server can record a response for a name the proxy is unsubscribing and then not re-send it when the re-added twin subscribes again. A real return (a new pod, a re-listing) comes seconds later.

3. Unit (cache, server and quicdemand):

  • TestLedger covers the transitions.
  • cache/quic_dormant_test.go:
    • source return and destination re-list, republished in the snapshot that makes the pair valid;
    • pairs with no subscription are forgotten as before;
    • persistence: dormant pairs survive an agent restart and are republished before any request when the ServiceAccount is present at load; absent ones stay dormant;
    • prune on a fresh stream that does not re-subscribe the pair (and kept when it does), and on a generation change (RestateQUICSubscriptions(nil));
    • a refused first use is parked.
  • server/quic_restate_test.go checks that the observer hands the cache every fresh stream's re-statement, including an empty one.

Runs

  • bazel … test --disk_cache= --test_output=errors //agent/... //test/...: 39/39 pass.
  • --config=race //agent/internal/xds/...: 8/8, clean.
  • build --config=lint --@aspect_rules_lint//lint:fail_on_violation //agent/... //test/... and //api/...: clean.
  • //:format and //:gazelle were run.

Docs

charts/ and agent/internal/xds/proxy/{capture,egress,ingress}.go are not touched.

Closes #1036

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 5 commits September 28, 2026 00:37
…set re-subscriptions are answered absent, and stale persisted pairs are pruned (#1033)

rev245 (the first talos deploy of #1032) logged observed_pairs ==
local_identities x 2 on every node: the fresh agent admitted, and
persisted, every twin the running proxy re-stated on the new xDS stream,
i.e. the SAs x destinations fan-out the previous agent had built up front.

- agent/internal/xds/quicdemand: classifies a delta CDS request's quic:
  names as first use (named on a later request, not held), resubscribed
  (a live on-demand subscription re-stated on a fresh stream) or held-only
  (initial_resource_versions via the wildcard).
- Held-only twins admit nothing (RestoreQUICTwin is gone); an unpersisted
  one is answered absent in removed_resources and Envoy drops it; the next
  routed request is a real on-demand fetch.
- Re-subscribed twins are served (ResumeQUICSubscriptions): Envoy's ODCDS
  manager keeps one subscription per name for the process lifetime and
  skips every later request for it, so answering one absent strands the
  pair (503 NC at the on_demand timeout). Shown live by the mtlspool
  strand control.
- Post-start prune: a persisted pair with no on-demand fetch or
  re-subscription within --east-west-quic-pair-fetch-window (default 1h)
  of the agent starting is dropped with its twin; one log line per node.

Gates (each seen red): server delta test (24 held twins, empty persisted
set -> 0 admitted, 24 removed; red: admitted=24), cache prune test, live
mtlspool agent-restart tests.

Closes #1033

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…ormant while its source or destination is away, republished on return, pruned only when the subscription is gone (#1036)

Envoy's ODCDS manager keeps one subscription per cluster name for the life
of the process. When the agent removed a twin the proxy had fetched on
demand (its source ServiceAccount's last pod left the node, or its
destination left the allow-list / dependency set), Envoy dropped the cluster
and kept the subscription; when a pod of that ServiceAccount came back, every
request to the twin was "already subscribed, skipping" -> 503 NC at the 2 s
on_demand timeout, until the proxy restarted.

quicdemand.Ledger records which twins the proxy holds an ODCDS subscription
for (first-use requests, refused or not, and fresh-stream re-subscriptions).
On removal evidence a subscribed pair goes dormant: its twin leaves the
snapshot, the pair is persisted in ObservedUpstreams.dormant_quic_pairs, and
the snapshot that sees it valid again republishes the twin with no request.
A dormant pair is pruned only when a fresh stream's first CDS request does
not re-subscribe it (agent restart against a proxy that no longer holds it,
or a hot-restart child). The fetch-window prune never touches a dormant or
subscribed pair.

Gates: //test/mtlspool TestOnDemandQUICDormantTwinRepublishedWhen{SourceReturns,
DestinationIsRelisted} (dormant: republished in 22 ms with no request, then
200/HTTP3 in 6.7 ms; forget_control: 503 in 2.000 s), cache/server/ledger
unit tests for the transitions, persistence and fresh-stream/generation prune.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
Resolves the 038 Selection conflict with #1034 (#1021 per-request cost) by
keeping both paragraphs: #1033's admission rule, then #1021's cost findings.

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

Keeps both sides: #1034's quic_cost_test.go and 038 per-request-cost
paragraph alongside #1036's quic_dormant_test.go and dormant-pair paragraph.

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

TestQUICDormantOnlyForSubscribedPairs flaked 2/8 under --config=race with
"TempDir RemoveAll cleanup: directory not empty": a 1 ms debounced flush
landed after the test returned. newQUICDemandCacheWith now registers a
FlushObservedUpstreams cleanup, which runs before TempDir's (LIFO) and
serializes with any in-flight write.

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

main's tree at c8f7df8 is identical to the #1035 branch head (556dbe8)
this branch already merged, so this merge records the squash as an
ancestor and keeps this branch's tree: main + the #1036 changes only.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 16f79ce into main Sep 28, 2026
24 checks passed
@bpalermo
bpalermo deleted the fix/1036-dormant-twin-pairs branch September 28, 2026 04:30
bpalermo added a commit that referenced this pull request Sep 29, 2026
Brings #979 up to date with 36 commits of main (demand-scoped twins #1020/#1032,
fresh-stream classifier #1033/#1035, dormant-pair ledger #1036/#1038, per-twin
EDS names #1012/#1029, the twin certificate gate #1051, the ODCDS always-answer
override, --east-west-quic-idle-timeout #1063, L4 stat keys #1043, access-log
timing #1048, the identity gate #1055, hot-restart knobs #1068 and the carried
Envoy patches) while keeping #979's intent: no allow-list, every destination in
the node's dependency set is QUIC-eligible.

Resolution:
- cache: quicServices / SetEastWestQUICServices removed. armsFor gives arms to
  every default, identity-ready, non-waypointed entry whose service is in the
  dependency set (the same rule recordQUICPair admits by, so no route names a
  twin the agent would refuse); twins stay demand-scoped. The
  destination_not_quic_enabled refusal/prune reason is gone.
- quicpairs: the dependency-set prune now waits for the pod set like the
  source prune does -- the allow-list used to force its destinations into the
  set, and without it the first snapshot after an agent restart dropped every
  restored pair (TestQUICDemandPairSurvivesAgentRestart was red).
- fan-out log: allow_listed_services dropped; observed_pairs and
  awaiting_client_cert kept.
- chart 1.0.12: eastWestQuicServices removed, eastWestQuicIdleTimeout and its
  parentShutdownTime check kept.
- e2e/eastwest-quic.sh: main's demand-scoped E1/E4c/E6 + #979's QUIC_DNS_SANS
  negative control; h2only/E3 removed; E6 dials quic-a and its idgate-* pairs
  are excluded from the driven-pair count. eastwest-quic-hotrestart.sh's h2
  control is now the weighted GAMMA split (the one h2-by-design path).
- tests, runbook, soak README, configuration.md, 038 rewritten for the
  unconditional state.

Co-Authored-By: Claude Opus 5.5 <[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

1 participant