Skip to content

Commit 674a524

Browse files
author
Bryan C. Mills
committed
[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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]> (cherry picked from commit 7e71c9c) Reviewed-on: https://go-review.googlesource.com/c/go/+/205517
1 parent 94b6eec commit 674a524

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ func runGet(cmd *base.Command, args []string) {
452452
// This includes explicitly requested modules that don't have a root package
453453
// and modules with a target version of "none".
454454
var wg sync.WaitGroup
455+
var modOnlyMu sync.Mutex
455456
modOnly := make(map[string]*query)
456457
for _, q := range queries {
457458
if q.m.Version == "none" {
@@ -464,7 +465,9 @@ func runGet(cmd *base.Command, args []string) {
464465
if hasPkg, err := modload.ModuleHasRootPackage(q.m); err != nil {
465466
base.Errorf("go get: %v", err)
466467
} else if !hasPkg {
468+
modOnlyMu.Lock()
467469
modOnly[q.m.Path] = q
470+
modOnlyMu.Unlock()
468471
}
469472
wg.Done()
470473
}(q)
Lines changed: 8 additions & 0 deletions
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)