]> Cypherpunks repositories - gostls13.git/commit
cmd/go: avoid registering AtExit handlers in tests
authorBryan C. Mills <bcmills@google.com>
Wed, 24 Aug 2022 13:45:18 +0000 (09:45 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 24 Aug 2022 15:37:38 +0000 (15:37 +0000)
commitd5aa088d822bc8ef3ceb80c20184f40fcb9b8d2e
tree1d8eed97adf92d277e33e882f84cf58bef805e2d
parentf983a9340d5660a9655b63a371966b5df69be8c5
cmd/go: avoid registering AtExit handlers in tests

Ever since 'go build' was added (in CL 5483069), it has used an atexit
handler to clean up working directories.

CL 154109 introduced 'cc' command to the script test framework that
called Init on a builder once per invocation. Unfortunately, since
base.AtExit is unsynchronized, the Init added there caused any script
that invokes that command to be unsafe for concurrent use.

This change fixes the race by having the 'cc' command pass in its
working directory instead of allowing the Builder to allocate one.
Following modern Go best practices, it also replaces the in-place Init
method (which is prone to typestate and aliasing bugs) with a
NewBuilder constructor function.

Fixes #54423.

Change-Id: I8fc2127a7d877bb39a1174e398736bb51d03d4d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/425205
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/go/internal/envcmd/env.go
src/cmd/go/internal/list/list.go
src/cmd/go/internal/run/run.go
src/cmd/go/internal/test/test.go
src/cmd/go/internal/vet/vet.go
src/cmd/go/internal/work/action.go
src/cmd/go/internal/work/build.go
src/cmd/go/script_test.go