Skip to content

fix(spire): test race so a redelivered SVID can never push twice (#1018) - #1019

Merged
bpalermo merged 1 commit into
mainfrom
fix/1018-node-svid-refresh-race
Sep 27, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/1018-node-svid-refresh-race

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Verdict: test race, not a code race

What raced. TestNodeSVIDRedeliveryCountsUnchanged takes its push baseline (pushesBefore) once bundle_updates{own,initial} reaches 1. But refreshWorkloadBundle records that counter before it calls pushSecrets. Interleaving on the failing runs:

  1. Initial wake (runIdentityRefresh goroutine): refreshNodeSVID → svid_updates{node,initial} → push Refactor registrar as xDS server #1 {agent:v1, vc:0}.
  2. Same wake: refreshWorkloadBundle bumps gen, records bundle_updates{own,initial}=1 …
  3. Test goroutine: counter is 1, reads gen() (already bumped) and len(store.snapshot()) == 1.
  4. Bridge goroutine: … pushSecrets → push Refactor registry #2 {agent:v1, vc:1}.
  5. Redelivery: correctly classified unchanged, no bump, no push. The test then sees 2 pushes vs baseline 1 → "an unchanged node SVID must not push".

Evidence: all 21/300 failing runs on main carry the same payload — the 2nd push is {…/aether-agent:1 validationContexts:1}, i.e. the initial wake's bundle push, not a push caused by the redelivery (which would carry the same state as push #2 and would have been collapsed by the publishedGen check anyway).

Why production is not affected. Refresh is already serialised: its only callers are Start (one synchronous refreshIdentity, then go runIdentityRefresh, so there is a happens-before) and the single runIdentityRefresh loop, which handles the Updated() wake and the 30 s tick in one select, one at a time. No two refreshes run concurrently, so there is no "both see nothing served yet" window. On top of that, pushSecrets drops a push whose generation is already published.

Fix

The test now waits for the observable effect of the initial wake's last push, the served generation (publishedGen == gen; publishedGen is written only after SetSecrets returns, under pushMu), before it takes the baseline. The "must not push" / "must not bump" assertions are unchanged.

Evidence

  • Seen red on main (98a84a8): bazel test --config=race --runs_per_test=300 --test_filter=TestNodeSVIDRedeliveryCountsUnchanged //agent/internal/spire:spire_test → FAILED in 21 out of 300, all with the signature above.
  • With this change: the same command → PASSED 300/300; unfiltered --config=race --runs_per_test=300 //agent/internal/spire:spire_test → PASSED 300/300.
  • bazel test //agent/internal/spire:all green; bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //agent/... green; bazel run //:format clean.

Closes #1018

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

TestNodeSVIDRedeliveryCountsUnchanged took its push baseline once the
bundle_updates{own,initial} counter reached 1, but refreshWorkloadBundle
records that counter BEFORE it calls pushSecrets. In that window the
baseline read 1 push, the initial wake's bundle push then landed as a 2nd,
and the "must not push" assertion blamed it on the redelivery.

Wait for the served generation (publishedGen == gen, written only after
SetSecrets returns) before taking the baseline. The assertion is unchanged.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 0570ac0 into main Sep 27, 2026
24 checks passed
@bpalermo
bpalermo deleted the fix/1018-node-svid-refresh-race branch September 27, 2026 21:19
bpalermo added a commit that referenced this pull request Sep 27, 2026
Brings in #1016 (repository-cache keys, cache-save: false, ci-bazel-warmup
first steps), #1019 and #1012. publish.yaml keeps both sides: the #1016
setup-bazel cache settings and warm-up step, then the release-environment
Quay robot login.

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

1 participant