Updates #35317
Fixes #35318
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: Jay Conrod <jayconrod@google.com>
(cherry picked from commit 
7e71c9c3edbf5b7a8608d6f739c20420a618e0ab)
Reviewed-on: https://go-review.googlesource.com/c/go/+/205517
 
        // 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" {
                                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)
 
--- /dev/null
+# 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