fix(cli): eliminate race in PausedDuringWaitForReady test#25858
Draft
mafredri wants to merge 1 commit into
Draft
fix(cli): eliminate race in PausedDuringWaitForReady test#25858mafredri wants to merge 1 commit into
mafredri wants to merge 1 commit into
Conversation
7c82faf to
a4219b9
Compare
The PausedDuringWaitForReady and WaitsForWorkingAppState tests flaked because the quartz resetTrap was released immediately after catching ticker.Reset (line 174), allowing client.TaskByID (line 175) to race with the subsequent DB mutation (pauseTask / PatchAppStatus). Fix: keep the resetTrap open across both poll iterations. On the first poll, release the trap so the goroutine sees the initial state and continues. On the second poll, hold the goroutine frozen at ticker.Reset while mutating state. Then release; client.TaskByID deterministically sees the mutated state. No race because the goroutine cannot execute client.TaskByID while trapped. Closes CODAGT-482
a4219b9 to
ec5a110
Compare
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
Test_TaskSend/PausedDuringWaitForReadyflakes on macOS CI with:Two prior fixes (PR #25648, PR #25811) added quartz mock clocks and
traps. The flake recurred on CI run 26634123539 (includes both fixes).
Root cause
The quartz
resetTrapwas released immediately after catchingticker.Reset(line 174 of task_send.go), then closed. This allowedclient.TaskByID(line 175, one line later) to race with the test'ssubsequent DB mutation (
pauseTask/PatchAppStatus).CI log evidence (run 26634123539, post-both-prior-fixes):
The GET and POST started 56us apart. The poll's 116ms DB query
straddled the stop build's commit, seeing
(stop, pending)which thetasks_with_statusview maps tounknown.WaitsForWorkingAppStatehas the same structural race (release trap,then mutate, then advance), though its race is benign since an early
mutation still makes the command succeed.
Fix
Test-only. Both
PausedDuringWaitForReadyand siblingWaitsForWorkingAppStateare fixed with the same pattern:resetTrapopen across both poll iterations (do notclose after the first poll)
ticker.Resetfreezing thegoroutine, release immediately. Goroutine proceeds to
client.TaskByID, sees initial state ("initializing" / "working"),continues polling
ticker.Resetagain,goroutine is frozen before
client.TaskByIDpauseTask/PatchAppStatus). The DB mutation completes with no concurrentreader
client.TaskByIDdeterministically sees the mutated state
No race because the goroutine cannot execute
client.TaskByIDwhiletrapped at
ticker.Reset.Verification
dlv session confirming the ordering gap (from investigation)
Breakpoints at
ticker.Reset(line 174) andclient.TaskByID(line175) confirm the trap fires between them:
After continuing, server logs show the concurrent requests that cause
the flake when the trap is released too early:
The fix eliminates this by holding the goroutine frozen at
ticker.Resetwhile the mutation runs.Closes CODAGT-482