From: Bryan C. Mills Date: Thu, 18 May 2023 12:20:54 +0000 (-0400) Subject: cmd/gofmt: fix a data race in TestPermissions X-Git-Tag: go1.21rc1~463 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7b0835d42de1deccd889451eda12390a56722ab7;p=gostls13.git 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 --- 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 {