Commit 7e71c9c3 authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/go/internal/modget: synchronize writes to modOnly map in runGet

Fixes #35317

Change-Id: Id858a25dc16a1bbff1802d25bcd4aca31c1133bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/205067
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJay Conrod <jayconrod@google.com>
parent f07cbc7f
...@@ -454,6 +454,7 @@ func runGet(cmd *base.Command, args []string) { ...@@ -454,6 +454,7 @@ func runGet(cmd *base.Command, args []string) {
// This includes explicitly requested modules that don't have a root package // This includes explicitly requested modules that don't have a root package
// and modules with a target version of "none". // and modules with a target version of "none".
var wg sync.WaitGroup var wg sync.WaitGroup
var modOnlyMu sync.Mutex
modOnly := make(map[string]*query) modOnly := make(map[string]*query)
for _, q := range queries { for _, q := range queries {
if q.m.Version == "none" { if q.m.Version == "none" {
...@@ -466,7 +467,9 @@ func runGet(cmd *base.Command, args []string) { ...@@ -466,7 +467,9 @@ func runGet(cmd *base.Command, args []string) {
if hasPkg, err := modload.ModuleHasRootPackage(q.m); err != nil { if hasPkg, err := modload.ModuleHasRootPackage(q.m); err != nil {
base.Errorf("go get: %v", err) base.Errorf("go get: %v", err)
} else if !hasPkg { } else if !hasPkg {
modOnlyMu.Lock()
modOnly[q.m.Path] = q modOnly[q.m.Path] = q
modOnlyMu.Unlock()
} }
wg.Done() wg.Done()
}(q) }(q)
......
# 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment