From 6ec46f470797ad816c3a5b20eece0995f13d2bc4 Mon Sep 17 00:00:00 2001 From: Rhys Hiltner Date: Mon, 16 May 2022 09:47:08 -0700 Subject: [PATCH] runtime/pprof: slow new goroutine launches in test The goroutine profiler tests include one that launches a steady stream of goroutines. That creates a scheduler busy loop that can prevent forward progress in the rest of the program. Slow down the launches a bit so other goroutines have a chance to run. Fixes #52916 For #52934 Change-Id: I748557201b94918b1fa4960544a51a48d9cacc6b Reviewed-on: https://go-review.googlesource.com/c/go/+/406654 TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Michael Knyszek --- src/runtime/pprof/pprof_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go index faefd857f0..aabc180de3 100644 --- a/src/runtime/pprof/pprof_test.go +++ b/src/runtime/pprof/pprof_test.go @@ -1527,6 +1527,10 @@ func TestGoroutineProfileConcurrency(t *testing.T) { SetGoroutineLabels(WithLabels(ctx, Labels(t.Name()+"-churn-i", fmt.Sprint(i)))) if i == 0 { ready.Done() + } else if i%16 == 0 { + // Yield on occasion so this sequence of goroutine launches + // doesn't monopolize a P. See issue #52934. + runtime.Gosched() } if ctx.Err() == nil { go churn(i + 1)