]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gofmt: fix a data race in TestPermissions
authorBryan C. Mills <bcmills@google.com>
Thu, 18 May 2023 12:20:54 +0000 (08:20 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 18 May 2023 12:52:14 +0000 (12:52 +0000)
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 <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/gofmt/gofmt_unix_test.go

index 45b923431207c1b7d00c0b3225453f7cb9b1028e..fec514380f6354f23760c295f8ef88d7113a2d9b 100644 (file)
@@ -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 {