Skip to content

Commit 765cc72

Browse files
millerresearchBryan Mills
authored and
Bryan Mills
committed
src/cmd/go/internal/work: lock Builder output mutex consistently
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 <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Trust: Russ Cox <[email protected]>
1 parent c27a359 commit 765cc72

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/cmd/go/internal/work/buildid.go

+4
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ func showStdout(b *Builder, c *cache.Cache, actionID cache.ActionID, key string)
570570
b.Showcmd("", "%s # internal", joinUnambiguously(str.StringList("cat", c.OutputFile(stdoutEntry.OutputID))))
571571
}
572572
if !cfg.BuildN {
573+
b.output.Lock()
574+
defer b.output.Unlock()
573575
b.Print(string(stdout))
574576
}
575577
}
@@ -578,6 +580,8 @@ func showStdout(b *Builder, c *cache.Cache, actionID cache.ActionID, key string)
578580

579581
// flushOutput flushes the output being queued in a.
580582
func (b *Builder) flushOutput(a *Action) {
583+
b.output.Lock()
584+
defer b.output.Unlock()
581585
b.Print(string(a.output))
582586
a.output = nil
583587
}

0 commit comments

Comments
 (0)