From 7b0835d42de1deccd889451eda12390a56722ab7 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 18 May 2023 08:20:54 -0400 Subject: [PATCH] cmd/gofmt: fix a data race in TestPermissions The asynchronous call to processFile is synchronized by the call to GetExitCode. We can't safely access errBuf until then, because processFile may still be writing to it. This is diagnosed by 'go test -race cmd/gofmt', but only the darwin-amd64-race builder caught it because the other "-race" builders apparently all run as root (see #10719). Updates #60225. Change-Id: Ie66bb4e47429ece81043d6425f26953b7bb26002 Reviewed-on: https://go-review.googlesource.com/c/go/+/496155 Auto-Submit: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Than McIntosh --- src/cmd/gofmt/gofmt_unix_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/gofmt/gofmt_unix_test.go b/src/cmd/gofmt/gofmt_unix_test.go index 45b9234312..fec514380f 100644 --- a/src/cmd/gofmt/gofmt_unix_test.go +++ b/src/cmd/gofmt/gofmt_unix_test.go @@ -50,12 +50,12 @@ func TestPermissions(t *testing.T) { s.Add(fileWeight(fn, info), func(r *reporter) error { return processFile(fn, info, nil, r) }) - if errBuf.Len() > 0 { - t.Log(errBuf) - } if s.GetExitCode() == 0 { t.Fatal("rewrite of read-only file succeeded unexpectedly") } + if errBuf.Len() > 0 { + t.Log(errBuf) + } info, err = os.Stat(fn) if err != nil { -- 2.50.0