]> git.feebdaed.xyz Git - 0xmirror/go.git/commit
cmd/go: fix race applying fixes in fix and vet -fix modes
authorAlan Donovan <adonovan@google.com>
Thu, 4 Dec 2025 20:29:49 +0000 (15:29 -0500)
committerGopher Robot <gobot@golang.org>
Fri, 5 Dec 2025 21:41:05 +0000 (13:41 -0800)
commitf3d572d96a25d1a0956ef828c0ff510ebf214d22
tree17613c7a4f52e15d1050b49a02e9cf4a479ded91
parent76345533f70e149511b1f50dbee598d0980cf867
cmd/go: fix race applying fixes in fix and vet -fix modes

Previously, the cmd/fix tool, which is analogous to a compiler
in a "go fix" or "go vet -fix" build, applied its fixes directly
to source files during the build. However, this led to races
since the edits may in some cases occur concurrently with other
build steps that are still reading those source file.

This change separates the computation of the fixes, which
happens during the build, and applying the fixes, which happens
in a phase after the build.

The unitchecker now accepts a FixArchive file name (see CL 726940).
If it is non-empty, the unitchecker will write the fixed files
into an archive instead of updating them directly.

The vet build sets this option, then reads the produced zip
files in the second phase. The files are saved in the cache;
some care is required to sequence the various cache operations
so that a cache hit has all-or-nothing semantics.

The tweak to vet_basic.txt is a sign that there was a latent
bug, inadvertently fixed by this change: because the old approach
relied on side effects of cmd/fix to mutate files, rather than
the current pure-functional approach of computing fixes which
are then applied as a second pass, a cache hit would cause some
edits not to be applied. Now they are applied.

Fixes golang/go#71859

Change-Id: Ib8e70644ec246dcdb20a90794c11ea6fd420247d
Reviewed-on: https://go-review.googlesource.com/c/go/+/727000
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@google.com>
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/exec.go
src/cmd/go/testdata/script/vet_basic.txt