Repository navigation
fix(agent): the initial snapshot waits for endpoints, not for a latch (#740) - #746
Merged
Merged
Conversation
…#740) On the rev211 deploy roll (2026-09-07 20:47Z) main-worker-02's agent published its initial xDS snapshot 0.4s after acquiring its SVID, while its registrar client's ClientConn was still recovering from the handshakes it had failed before identity existed. The registry read failed, the snapshot went out with no cross-node endpoints, and that node's prober logged 316 http_error over the ~30s until the next refresh repaired it — with SPIRE healthy and both registrar replicas Ready since 20:46:45Z. What registryReady meant: PreListen type-asserted registry.ReadyWaiter (registry/registry.go:52-59) and called WaitReady (registry/internal/registrar/registrar.go:207-214), which blocks on a ONE-SHOT latch closed by readyOnce at registrar.go:799 on the first SNAPSHOT_COMPLETE. So it meant "a complete snapshot arrived at some point" — not "the registry will serve this read now". The read that follows takes a different path (the RPC fallback at registrar.go:377-397 when the cache is not serving), and its failure was handled by the local-only fallback, not by more waiting. So the wait now ends on a SUCCESSFUL load: WaitReady, then LoadClustersFromRegistry retried inside the same 15s budget the ready-wait already had, logging `registry connected; generating the initial snapshot` with the elapsed wait. A genuinely unreachable registrar costs exactly what it cost before — the budget, then the unchanged local-only fallback and background retry. Synchronous backends (no watch) keep the single attempt exactly. Nothing else in PreListen moves: #700/#712's AssertWatchFilter ordering stands. Classification, second half. `x509svid: could not get X509 bundle` is raised by go-spiffe's own verifier against the LOCAL bundle source (svid/x509svid/verify.go:59-61), so the identical text is produced whichever party was short of an identity — and after a pre-identity attempt the ClientConn hands it back from cache, so it is not even current. Text cannot classify it; local state can. spire.ClassifyHandshake asks in the order the answers are trustworthy: our own IdentityReady() first, then a transport failure inside a 5s window after identity arrived (the reconnect), and only then the peer's. Both the cluster-refresh path (reportReloadFailure, PR 4) and the watch loop use it. New INFO `registrar connection not yet re-established after identity; retrying`; `registrar has no identity yet` now means what it says. #718's drain classification is untouched (it never reaches failStream). Tests, all hermetic: a watch-backed registry whose readiness latch is already satisfied while reads still fail for 400ms — PreListen must not return before it can serve, and the published snapshot must carry its cluster and endpoint; a control proving the failed attempts publish nothing; the never-comes-up registry still falling back local-only inside its bound; the synchronous-backend control; and the three-way classification in common/spire, the refresher and the registrar client. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
This was referenced Sep 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 5 of #740. A race found on the rev211 deploy roll: with SPIRE healthy and both registrar replicas Ready since 20:46:45Z,
main-worker-02's agent produced a 316-requesthttp_errorburst on that node's prober (~30s at 10 rq/s).The timeline (all 2026-09-07, within 3 seconds)
Once identity is acquired,
PreListengenerated and published the initial snapshot immediately, but the registrar client's connection was still recovering from its pre-identity handshake failures (ResetConnectBackoffat 27.911; the watch connected at 29.017). The registry list failed, the first snapshot Envoy received had no cross-node endpoints, and the next refresh (~30s) repaired it.What
registryReadymeantPreListentype-assertedregistry.ReadyWaiter(registry/registry.go:52-59) and calledWaitReady(registry/internal/registrar/registrar.go:207-214), which blocks on a one-shot latch closed byreadyOnceatregistrar.go:799on the firstSNAPSHOT_COMPLETE.So it meant "a complete snapshot arrived at some point" — not "the registry will serve this read now":
AssertWatchFilter(server.go:150) has purged cache entries leaving the filter and forced a re-filtered resnapshot;ListAllEndpointsfalls through to the RPC fallback (registrar.go:377-397) whenever the cache is not serving — and that path fails on a ClientConn still in its handshake-failed state;The fix
The initial snapshot waits for endpoints, not for a latch.
loadInitialRegistryConfigkeepsWaitReadyand then retriesLoadClustersFromRegistryinside the same 15s budget the ready-wait already had, ending only on a successful load. New INFOregistry connected; generating the initial snapshotwithwaited=. A genuinely unreachable registrar costs exactly what it cost before — the budget, then the unchangedregistry unavailable for initial snapshot; starting with local-only configand the background retry. Failed attempts publish nothing (LoadClustersFromRegistryreturns before touching the snapshot), so Envoy never sees an endpoint-less generation on the way to the good one. Registries with no watch (synchronous backends) keep the single attempt exactly. Nothing else inPreListenmoves — agent: first registrar watch-stream attempt logs ERROR 'context canceled' on a clean startup, then retries fine #700/fix(agent): stop logging the startup watch-stream handoff as an ERROR (#700) #712'sAssertWatchFilterordering stands.Classification order. The two
x509svid: could not get X509 bundlecases are textually identical, and the reason is structural: that string is raised by go-spiffe's own verifier against the local bundle source (svid/x509svid/verify.go:59-61), so it is produced whichever party was short — and after a pre-identity attempt the gRPC ClientConn hands it back from cache, so it is not even current. (A peer that cannot present a certificate at all arrives as aremote error: tls: …alert instead.) Text therefore cannot name the party; local state can. Newspire.ClassifyHandshake(err, identityReady, sinceIdentity)asks in the order the answers are trustworthy:IdentityReady()false →deferred until this agent has an SVID;UnavailablewithinReconnectWindow(5s) of identity arriving → INFOregistrar connection not yet re-established after identity; retrying;registrar has no identity yet.Used by both the cluster-refresh path (
reportReloadFailure, fix(registrar,controller,edge): NotReady until identity, not after a dwell (#740) #744) and the watch loop (failStream). The window's anchor isNotifyIdentityReady, stamped once; a client never told about identity (SPIRE off) gets no window and keeps its pre-PR-5 classification byte for byte. agent: registrar watch stream logs ERROR 'watch stream disconnected … received prior goaway' on every registrar roll; a server-initiated GOAWAY is a graceful handoff, not a failure #718's drain classification is untouched — an established stream ending on aNO_ERRORGOAWAY returns no failure and never reachesfailStream.Tests (hermetic, no cluster, no sleep-based flake): a watch-backed fake whose readiness latch is already satisfied while reads keep failing for 400ms —
PreListenmust not return before the registry can serve, and the published snapshot must carry the fake registry's cluster and its endpoint IP; a control run proving the failed attempts publish nothing (same snapshot generation as a registry that was serving all along); the never-comes-up registry still falling back local-only inside its bound (existing behaviour, kept); the synchronous-backend negative control; and the three-way classification pinned incommon/spire, in the refresher, and in the registrar client — with the agent: first registrar watch-stream attempt logs ERROR 'context canceled' on a clean startup, then retries fine #700 ERROR path as the negative control in each.Runbook: a paragraph in The agent is stuck waiting for SPIRE on
registry connected; generating the initial snapshotand on reading the reconnect INFO as ours rather than the registrar's.No chart change.
Validation
bazel test --test_arg=-test.short //agent/... //common/... //registry/...— 56/56 pass.make gazelle,bazel build --config=linton the touched packages,make format-checkall clean.On talos: a plain
kubectl -n aether rollout restart ds/aether-agentmust produce 0 mesh_dnshttp_erroron every node — the rev211 roll produced 316 onmain-worker-02. Grade per node against a pre-roll baseline of the prober counters, and expectregistry connected; generating the initial snapshotonce per agent withwaitedin the tens-of-ms to ~1s range,registrar has no identity yetonly when a registrar replica really is starting, and zeroregistry unavailable for initial snapshot.🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr