]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/go: work around race in fmtCmd
authorAustin Clements <austin@google.com>
Wed, 18 Oct 2023 20:49:50 +0000 (16:49 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 18 Oct 2023 21:09:43 +0000 (21:09 +0000)
CL 529219 made an existing race with accessing Builder.scriptDir from
Builder.fmtcmd (and now also Builder.Showcmd) much more likely by
dropping a theoretically unnecessary condition from the call from
Builder.run to Builder.fmtcmd.

For an example race report, see
https://build.golang.org/log/c3cad62d0fc33a8381d2091661c685ea1fc525c4

The race is between

  (*Builder).cover2() -> (*Builder).run() -> (*Builder).fmtcmd()

and various other call paths of the form

  (*Builder).build() -> (*gcToolchain).*  (*Builder).Showcmd() -> (*Builder).fmtcmd()

The race can be reproduced with

  go install -race cmd/go
  stress -p 1 go test -x -cover -a log

Return this race to its existing likelihood by putting the condition
back. This isn't a "correct" solution because the race could still
happen if the "cover" tool invoked by Builder.cover2 emits output. But
this will do for a temporary fix.

Change-Id: Ifd811dea07f05e1422fd02b63cd958627727aa12
Reviewed-on: https://go-review.googlesource.com/c/go/+/536355
Auto-Submit: Austin Clements <austin@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/go/internal/work/exec.go

index f115b5dc47715ac7ec6a757cc3229958e0615c8d..d66ffb7b86e44fffcc887db4028bc5701cdb2309 100644 (file)
@@ -2389,7 +2389,7 @@ var cgoTypeSigRe = lazyregexp.New(`\b_C2?(type|func|var|macro)_\B`)
 // and returns a non-nil error.
 func (b *Builder) run(a *Action, dir string, desc string, env []string, cmdargs ...any) error {
        out, err := b.runOut(a, dir, env, cmdargs...)
-       if desc == "" {
+       if len(out) > 0 && desc == "" {
                desc = b.fmtcmd(dir, "%s", strings.Join(str.StringList(cmdargs...), " "))
        }
        return b.reportCmd(a, desc, dir, out, err)