Skip to content

Commit 7e71c9c

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent f07cbc7 commit 7e71c9c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/cmd/go/internal/modget/get.go

+3
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ func runGet(cmd *base.Command, args []string) {
454454
// This includes explicitly requested modules that don't have a root package
455455
// and modules with a target version of "none".
456456
var wg sync.WaitGroup
457+
var modOnlyMu sync.Mutex
457458
modOnly := make(map[string]*query)
458459
for _, q := range queries {
459460
if q.m.Version == "none" {
@@ -466,7 +467,9 @@ func runGet(cmd *base.Command, args []string) {
466467
if hasPkg, err := modload.ModuleHasRootPackage(q.m); err != nil {
467468
base.Errorf("go get: %v", err)
468469
} else if !hasPkg {
470+
modOnlyMu.Lock()
469471
modOnly[q.m.Path] = q
472+
modOnlyMu.Unlock()
470473
}
471474
wg.Done()
472475
}(q)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Regression test for golang.org/issue/35317:
2+
# 'go get' with multiple module-only arguments was racy.
3+
4+
env GO111MODULE=on
5+
[short] skip
6+
7+
go mod init example.com
8+
go get golang.org/x/[email protected] golang.org/x/[email protected]

0 commit comments

Comments
 (0)