Skip to content

Commit 7b0835d

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
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 <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent 75add1c commit 7b0835d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/cmd/gofmt/gofmt_unix_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ func TestPermissions(t *testing.T) {
5050
s.Add(fileWeight(fn, info), func(r *reporter) error {
5151
return processFile(fn, info, nil, r)
5252
})
53-
if errBuf.Len() > 0 {
54-
t.Log(errBuf)
55-
}
5653
if s.GetExitCode() == 0 {
5754
t.Fatal("rewrite of read-only file succeeded unexpectedly")
5855
}
56+
if errBuf.Len() > 0 {
57+
t.Log(errBuf)
58+
}
5959

6060
info, err = os.Stat(fn)
6161
if err != nil {

0 commit comments

Comments
 (0)