Skip to content

Commit

Permalink
src/cmd/go/internal/work: lock Builder output mutex consistently
Browse files Browse the repository at this point in the history
To prevent interleaving of output when 'go build' compiles several
packages in parallel, the output mutex in the Builder struct must
be locked around any calls to Builder.Print which could generate
arbitrary amounts of text (ie more than is guaranteed to be written
atomically to a pipe).

Fixes #49987
For #49338

Change-Id: I7947df57667deeff3f03f231824298d823f8a943
Reviewed-on: https://go-review.googlesource.com/c/go/+/369018
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Russ Cox <rsc@golang.org>
  • Loading branch information
millerresearch authored and Bryan Mills committed Dec 6, 2021
1 parent c27a359 commit 765cc72
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cmd/go/internal/work/buildid.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ func showStdout(b *Builder, c *cache.Cache, actionID cache.ActionID, key string)
b.Showcmd("", "%s # internal", joinUnambiguously(str.StringList("cat", c.OutputFile(stdoutEntry.OutputID))))
}
if !cfg.BuildN {
b.output.Lock()
defer b.output.Unlock()
b.Print(string(stdout))
}
}
Expand All @@ -578,6 +580,8 @@ func showStdout(b *Builder, c *cache.Cache, actionID cache.ActionID, key string)

// flushOutput flushes the output being queued in a.
func (b *Builder) flushOutput(a *Action) {
b.output.Lock()
defer b.output.Unlock()
b.Print(string(a.output))
a.output = nil
}
Expand Down

0 comments on commit 765cc72

Please sign in to comment.