Skip to content

fix(quic): answer ODCDS for a known twin immediately and never absent — first use after an agent restart no longer trips Envoy's on-demand timeout (#1049) - #1051

Merged
bpalermo merged 2 commits into
mainfrom
fix/1049-twin-first-use-latency
Sep 28, 2026

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Where the seconds went (rev248 phase C, from the agents' own logs)

The issue asked whether the twin was queued behind a full-snapshot rebuild or a debounce. It was not. Every agent published every twin within 10 ms of the need for it. The time was spent in Envoy, warming a twin whose client certificate did not exist yet.

These timelines come from kubectl logs of the rev248 agent pods, which were still running. The proxy logs are from the issue.

main-worker-02, first-use pair:

  1. 15:44:46.116 k6 loader pod CNI ADD (server/pod.go:108). It is the node's first pod of SA aether-test/default. The agent opens its SVID subscription at 15:44:46.130 (spire/bridge.go:316).
  2. 15:44:46.3 the pod's inbound chains reference spiffe://aether.internal/ns/aether-test/sa/default, which is absent from the snapshot (inboundidentitybinding.go:235).
  3. 15:44:49.996 the proxy's ODCDS request for quic:svc-2…@aether-test/default arrives. onDeltaRequest (server/odcds.go:98) calls observeQUICTwin (:108), which calls ObserveQUICTwin (cache/quicpairs.go:76). The pair is admitted and generateSnapshot runs on its own goroutine (:83).
  4. 15:44:50.006 SetSnapshot with the twin and its CLA (cache/snapshot.go:220). That is 10 ms after the request. snapshotMu (:41) was free, and the registry reload's slow part, the listing, holds no cache lock.
  5. The twin names its source's SVID statically: QUICClusterFrom (proxy/egress.go:319) calls QUICUpstreamTransportSocket, which calls sdsSecretConfig(clientSpiffeID) (proxy/transportsocket.go:308). That secret is still not in the snapshot, so Envoy keeps the twin warming on SDS.
  6. ≈15:44:52.2 the on_demand filter's timeout fires (onDemandClusterTimeout = 2s, proxy/httpfilter.go:32). Result: 503 NC.
  7. 15:44:53.526 SPIRE delivers the pod's first SVID (update=initial). The next snapshot carries the secret, the twin warms, and traffic flows. That is 7.4 s after the CNI ADD.

main-worker-04 and main-worker-03, dormant pair:

  1. The CNI ADD at 15:44:45.995 / 46.101 revives the dormant pairs (reviveDormantQUICPairsLocked, cache/quicpairs.go:326) and SetSnapshot runs at 46.057 / 46.116, 5 ms later.
  2. The twin warms on the same missing secret until 15:44:52.990 / 53.431.
  3. The proxy's request at ≈50.2 times out at 52.2, even though the twin was "republished" at 46.0.

main-worker-03 not found during on-demand discovery at 15:45:04.7. The agent published no snapshot between 15:44:53.4 and 15:45:43, so this is not an absent answer from the snapshot. The sequence:

  1. The wildcard CDS subscription delivered the twin at 46.1.
  2. At ≈49.7 a request routed to it while it was still warming. Envoy's ODCDS manager then subscribed to the name on the same stream (XdstpOdcdsSubscriptionsManager, od_cds_api_impl.cc).
  3. go-control-plane answers a named subscribe only when the version differs from what the stream was sent (createDeltaResponse in v0.14.0), so it sent nothing.
  4. The per-name subscription waited out its 15 s initial-fetch timeout. onConfigUpdateFailed then called onFailure, which called notifyMissingCluster (cm odcds: … not found) at 49.7 + 15.0 = 04.7.

Any request still waiting on the name at that moment would have been failed as missing.

Fix

Tests (each seen red with the fix disabled, green with it)

  • cache/quic_cert_gate_test.go:
    • TestQUICTwinAndArmWaitForTheSourceCertificate. Red: source-c's twin and arm are published with no certificate.
    • TestQUICDormantPairReturnAfterLedgerReloadWaitsForCertificate, the incident's shape: dormant pair, ledger reload, restate, the source's pod returns without its SVID, then the SVID arrives. Red: Should be empty, but was [quic:echo…@demo/source-a].
    • TestQUICCertificateGateInactiveWithoutAnySecret.
    • TestQUICFirstUsePublishedWhileARegistryReloadIsInFlight, the timing gate. A registry reload is blocked in its listing throughout, and the twin still reaches the snapshot in 1.7 ms (must be < 1 s).
  • server/quic_first_use_test.go, real delta server over bufconn:
    • TestOnDemandSubscribeForATwinTheWildcardAlreadySentIsAnswered: answered in ~117 µs. Red: no response within 2 s.
    • TestOnDemandTwinWaitingForItsCertificateIsHeldNeverAbsent: first use with SPIRE live but no source SVID. The pair is admitted, the subscription is held with no removed_resources, and the twin arrives on the stream when SetSecrets brings the certificate. Red: the twin is served before its certificate.
  • Existing tests are unchanged and green:
    • bazel test //agent/internal/xds/... //test/envoy_validate:all (9/9)
    • --config=race //agent/internal/xds/cache:all //agent/internal/xds/server:all
    • build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...
    • make format-check

Docs

Not changed / open

Closes #1049

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits September 28, 2026 14:32
… — first use after an agent restart no longer trips Envoy's on-demand timeout (#1049)

rev248 phase C: the agent published every twin within 10 ms of the need
for it, but a twin names its source's SVID statically, and SPIRE delivered
the new k6 pods' SVIDs 6.9-7.4 s after their CNI ADD. The twins warmed on
SDS, the on_demand filter's 2 s timeout fired first: 428 x 503 NC.

- An identity whose client certificate is not in the snapshot yet gets
  neither a selection arm nor a twin (its requests ride the warm h2
  cluster); the certificate's snapshot carries arm, twin and CLA together.
  The fan-out line reports awaiting_client_cert.
- A named CDS subscribe for a quic: twin the stream already received via
  the wildcard is answered with the twin (SnapshotCache.CreateDeltaWatch).
  go-control-plane stayed silent on it, Envoy's per-name ODCDS subscription
  hit its 15 s initial-fetch timeout and reported the twin missing
  (main-worker-03, 15:45:04.7).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 0173c39 into main Sep 28, 2026
24 checks passed
@bpalermo
bpalermo deleted the fix/1049-twin-first-use-latency branch September 28, 2026 17:41
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