From 00a053bd4b2c19b2d9680f78f4c8657fcc6f1c88 Mon Sep 17 00:00:00 2001 From: Michał Łowicki Date: Sun, 23 Aug 2020 23:53:04 +0100 Subject: testing: fix Cleanup race with Logf and Errorf Fixes #40908 Change-Id: I25561a3f18e730a50e6fbf85aa7bd85bf1b73b6e Reviewed-on: https://go-review.googlesource.com/c/go/+/250078 Reviewed-by: Tobias Klauser Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot --- src/testing/testing.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/testing') diff --git a/src/testing/testing.go b/src/testing/testing.go index 6fc8c4fa9f..bf83df8863 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -860,11 +860,15 @@ func (c *common) Cleanup(f func()) { c.cleanup = func() { if oldCleanup != nil { defer func() { + c.mu.Lock() c.cleanupPc = oldCleanupPc + c.mu.Unlock() oldCleanup() }() } + c.mu.Lock() c.cleanupName = callerName(0) + c.mu.Unlock() f() } var pc [maxStackLen]uintptr -- cgit v1.3