Repository navigation
Stop the DCR recheck tests racing their loop - #7172
Conversation
Two tests build an embedded auth server with a RegistrationProbeInterval, which also starts the background re-check loop, and then call tick by hand to drive the re-check. The loop's first tick fires at a random moment in the first minute, so it sometimes ran during the test. The two ticks then touched the re-check's current resolution at the same time (a data race), and the background tick could spend the initial access token the test meant to use, giving ["iat-1","iat-1"] instead of ["iat-1","iat-2"]. Stop the loop right after the server is built, so the manual ticks are the only ones. Production only ticks from the loop, so no production change is needed. Co-authored-by: Mecatl <[email protected]>
rdimitrov
left a comment
There was a problem hiding this comment.
Draft review: no significant findings; this looks right to approve once it is marked ready.
Design: The flake comes from NewEmbeddedAuthServerWithStorage starting the DCR re-check goroutines immediately, while these two tests also drive re-checks by hand with tick(), so a background tick could race on r.current. Stopping the loop in the tests is the right place for the fix: production should keep the loop running, and stopDCRRechecks is synchronous (cancel + wg.Wait) and idempotent, so the later Close call is safe. These are the only two tests that build a full EmbeddedAuthServer with RegistrationProbeInterval and call tick() manually, and the loop itself stays covered by TestStartDCRRechecks_StopsLoops. No production code or upgrade behaviour changes.
🤖 Reviewed with Claude Code
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7172 +/- ##
==========================================
+ Coverage 81.39% 81.41% +0.02%
==========================================
Files 890 890
Lines 90704 90736 +32
==========================================
+ Hits 73831 73877 +46
+ Misses 16868 16854 -14
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
TestEmbeddedAuthServer_DCRRecheckFollowsMovedTokenEndpointfailed once in CI with a data race andexpected: ["iat-1","iat-2"] actual: ["iat-1","iat-1"]. The test builds an embedded auth server withRegistrationProbeInterval: "1m", which also starts the background re-check loop. The loop's first tick fires at a random point in the first minute, and the test callstickby hand as well. When the loop's tick lands during the test, the two ticks overlap: both touchcurrentintickwithout synchronisation, and the background tick can use up the initial access token the test wanted to present.TestEmbeddedAuthServer_DCRRecheckRecoversWithoutRestartandTestEmbeddedAuthServer_DCRRecheckFollowsMovedTokenEndpoint), so the manual ticks are the only ones.Type of change
Test plan
task test): ran itsgo test -raceflags scoped to./pkg/authserver/runner/(the re-check tests 20 times, the whole package twice), not the whole repo. CI runs the rest.task lint-fix): rangolangci-lint run ./pkg/authserver/runner/...on the package only, 0 issues;gofmtandgo vetclean.MinRegistrationProbeIntervaland set the tests' interval to 5ms. Before the fix, 20 runs with-racegave 38 failing test runs, including the same["iat-1","iat-1"]assertion and a data race atdcr_recheck.go:166. After the fix, 60 runs with the same forcing were clean. The forcing edit is not part of this change.Does this introduce a user-facing change?
No
Special notes for reviewers
tickfromrun(), so there is no race in the product, only in how the tests used the loop. That is why the fix is test-only and adds no lock.stopDCRRechecksis the function the server already uses inClose. It cancels the loop and waits for in-flight ticks, and calling it again fromCloseis harmless.tickon adcrRecheckthey build themselves, with no loop running, so they are not affected.