Skip to content

Commit

Permalink
runtime: usleep in TestWeakToStrongMarkTermination
Browse files Browse the repository at this point in the history
There's a subtle bug in this test (big surprise): time.Sleep allocates,
so the time.Sleep(100*time.Millisecond) before unblocking gcMarkDone
might itself end up in gcMarkDone.

Work around this by using usleep here instead.

Fixes #70532.

Change-Id: I4c642ebb12f737cdb0d79ccff64b6059fc3d8b34
Reviewed-on: https://go-review.googlesource.com/c/go/+/636155
Reviewed-by: Cherry Mui <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
mknyszek committed Dec 16, 2024
1 parent 18b5435 commit 3bd08b9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/runtime/gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,11 @@ func TestWeakToStrongMarkTermination(t *testing.T) {
done <- struct{}{}
}()
go func() {
time.Sleep(100 * time.Millisecond)
// Usleep here instead of time.Sleep. time.Sleep
// can allocate, and if we get unlucky, then it
// can end up stuck in gcMarkDone with nothing to
// wake it.
runtime.Usleep(100000) // 100ms

// Let mark termination continue.
runtime.SetSpinInGCMarkDone(false)
Expand Down

0 comments on commit 3bd08b9

Please sign in to comment.