Repository navigation
test(b2): make the reauth waiter test deterministic - #238
Merged
Merged
Conversation
The fake b2_authorize_account handler held the leader's reauthorization until the leader was cancelled, then still answered it with success and the expired token. If that response beat the client's cancellation, blazer correctly recorded a successful refresh with the stale token, the waiter reused it, and the test failed with 401 expired (seen once in CI). Never answer the leader's reauthorization while the test runs; release it at cleanup, which runs before the recording server's own cleanup. The leader now always ends through its cancelled context, and the R4 break (ignoring leaderContextExpired) fails the test on every run. Closes #237
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified, though tests were not independently run.
No open issues 🎉
What changed in this PR
No issues found. This test-only change addresses #237 by removing the response-versus-cancellation race in the reauthorization waiter regression test. Production behavior is unchanged.
Changes:
- Block the leader’s authorization handler until test cleanup, ensuring cancellation ends its request.
- Release the handler before server cleanup to avoid hanging teardown.
Checked the supplied diff; tests were not independently run.
| File | Description |
|---|---|
b2/bucket_mapping_edges_test.go |
Adds a cleanup-controlled channel and documents why the blocked authorization must not respond during the test. |
Review effort: Balanced
david-santacruz-backblaze
approved these changes
Oct 30, 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.
Problem
TestMappingReauthWaiterSurvivesCancelledLeader, added in #224 for #201's R4, failed intermittently in CI. It was seen on #211 (Go 1.27.3,ubuntu-latest,-race -shuffle=on, seed1793310626879098904):It did not reproduce locally with that seed or in 200 isolated runs, so it is timing-dependent and can fail any PR's CI.
Root cause (test fixture, not blazer)
The fake
b2_authorize_accounthandler blocked the leader's reauthorization (call 2) until the test cancelled the leader, and then still answered it with success, using the expired token"t".context.Canceled. The waiter then reauthorized itself and got the"fresh"token, as the test intends.401 expiredagain.Blazer was correct in both orderings. The fixture should never report a successful refresh with an expired token.
Fix
Test-only, 8 lines in
b2/bucket_mapping_edges_test.go. The leader's reauthorization now never gets an answer while the test runs. The handler waits on a channel that is closed at test cleanup, so the leader can only end through its cancelled context. That cleanup is registered afterb2wiretest.New, so it runs before the recording server's own cleanup (t.Cleanupruns in reverse order), which waits for active handlers to return.Verification
go test -race -count=500 -run '^TestMappingReauthWaiterSurvivesCancelledLeader$' ./b2passes.if flight.leaderContextExpired→if falseinb2/backend.go) now fails 50 out of 50 runs:waiter error = context canceled, want nil. It passes when restored.go test -race -count=3 -shuffle=on ./b2passes, andmake cipasses, withB2_APPLICATION_KEY_ID,B2_APPLICATION_KEY,B2_ACCOUNT_IDandB2_ACCOUNT_KEYunset.Notes for reviewers
Writerpanic in fix(b2): Writer.Write panics when copyContext keeps writing after the call returns (flaky CI) #229 / fix(b2): stop a cancelled copy from writing after copyContext returns #236. This is a separate flaky test.maindirectly.Closes #237