From 6328e445c3a87d64a32b6203af3f39d43d874f9f Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Fri, 21 Apr 2023 11:42:20 -0400 Subject: [PATCH] log: avoid leaking goroutines in TestOutputRace Leaked goroutines are the only explanation I can think of for excess allocs in TestDiscard, and TestOutputRace is the only place I can see where the log package leaks goroutines. Let's fix that leak and see if it eliminates the TestDiscard flakes. Fixes #58797 (maybe). Change-Id: I2d54dcba3eb52bd10a62cd1c380131add6a2f651 Reviewed-on: https://go-review.googlesource.com/c/go/+/487356 TryBot-Result: Gopher Robot Auto-Submit: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Ian Lance Taylor --- src/log/log_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/log/log_test.go b/src/log/log_test.go index b3b63d4e22..c7fa78f5ad 100644 --- a/src/log/log_test.go +++ b/src/log/log_test.go @@ -109,12 +109,16 @@ func TestNonNewLogger(t *testing.T) { func TestOutputRace(t *testing.T) { var b bytes.Buffer l := New(&b, "", 0) + var wg sync.WaitGroup + wg.Add(100) for i := 0; i < 100; i++ { go func() { + defer wg.Done() l.SetFlags(0) l.Output(0, "") }() } + wg.Wait() } func TestFlagAndPrefixSetting(t *testing.T) { -- 2.48.1