From 3bd08b97921826c1b0a5fbf0789f4b49d7619977 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Fri, 13 Dec 2024 23:18:59 +0000 Subject: [PATCH] runtime: usleep in TestWeakToStrongMarkTermination 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 LUCI-TryBot-Result: Go LUCI --- src/runtime/gc_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/runtime/gc_test.go b/src/runtime/gc_test.go index 35cb634936a91e..00280ed1b53cab 100644 --- a/src/runtime/gc_test.go +++ b/src/runtime/gc_test.go @@ -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)