From: Bryan C. Mills Date: Mon, 4 Nov 2019 04:40:44 +0000 (-0500) Subject: [release-branch.go1.13] cmd/go/internal/modget: synchronize writes to modOnly map... X-Git-Tag: go1.13.5~7 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=674a524a3f4fa5be6f7335f292d0d7fae4e8553e;p=gostls13.git [release-branch.go1.13] cmd/go/internal/modget: synchronize writes to modOnly map in runGet Updates #35317 Fixes #35318 Change-Id: Id858a25dc16a1bbff1802d25bcd4aca31c1133bc Reviewed-on: https://go-review.googlesource.com/c/go/+/205067 Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot Reviewed-by: Jay Conrod (cherry picked from commit 7e71c9c3edbf5b7a8608d6f739c20420a618e0ab) Reviewed-on: https://go-review.googlesource.com/c/go/+/205517 --- diff --git a/src/cmd/go/internal/modget/get.go b/src/cmd/go/internal/modget/get.go index 1cae311c4c..d234a1eb0b 100644 --- a/src/cmd/go/internal/modget/get.go +++ b/src/cmd/go/internal/modget/get.go @@ -452,6 +452,7 @@ func runGet(cmd *base.Command, args []string) { // This includes explicitly requested modules that don't have a root package // and modules with a target version of "none". var wg sync.WaitGroup + var modOnlyMu sync.Mutex modOnly := make(map[string]*query) for _, q := range queries { if q.m.Version == "none" { @@ -464,7 +465,9 @@ func runGet(cmd *base.Command, args []string) { if hasPkg, err := modload.ModuleHasRootPackage(q.m); err != nil { base.Errorf("go get: %v", err) } else if !hasPkg { + modOnlyMu.Lock() modOnly[q.m.Path] = q + modOnlyMu.Unlock() } wg.Done() }(q) diff --git a/src/cmd/go/testdata/script/mod_issue35317.txt b/src/cmd/go/testdata/script/mod_issue35317.txt new file mode 100644 index 0000000000..003390b710 --- /dev/null +++ b/src/cmd/go/testdata/script/mod_issue35317.txt @@ -0,0 +1,8 @@ +# Regression test for golang.org/issue/35317: +# 'go get' with multiple module-only arguments was racy. + +env GO111MODULE=on +[short] skip + +go mod init example.com +go get golang.org/x/text@v0.3.0 golang.org/x/internal@v0.1.0