Skip to content

Commit 6dbcc8b

Browse files
author
Bryan C. Mills
committed
cmd/go: make "finding" logging deterministic
In CL 204777, I made the "finding" messages in cachingRepo only print after a “longish” delay, on the theory that they would help diagnose slow or stuck fetches. However, as I've been testing Go 1.14 beta 1, I've found that these messages are mostly just noise, and the fact that they are so nondeterministic causes both confusion and test flakes (#35539). Moreover, it currently triggers once for each candidate module, when what we're usually after is actually a specific package within the module. So let's log the package operation unconditionally instead of the module fetches nondeterministically. Fixes #35539 Updates #26152 Change-Id: I41a1c772465b2f0b357d3402bc372b6907773741 Reviewed-on: https://go-review.googlesource.com/c/go/+/213679 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
1 parent 17e9732 commit 6dbcc8b

File tree

3 files changed

+4
-18
lines changed

3 files changed

+4
-18
lines changed

src/cmd/go/internal/modfetch/cache.go

-18
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"os"
1414
"path/filepath"
1515
"strings"
16-
"time"
1716

1817
"cmd/go/internal/base"
1918
"cmd/go/internal/cfg"
@@ -28,8 +27,6 @@ import (
2827

2928
var PkgMod string // $GOPATH/pkg/mod; set by package modload
3029

31-
const logFindingDelay = 1 * time.Second
32-
3330
func cacheDir(path string) (string, error) {
3431
if PkgMod == "" {
3532
return "", fmt.Errorf("internal error: modfetch.PkgMod not set")
@@ -140,11 +137,6 @@ func (r *cachingRepo) Versions(prefix string) ([]string, error) {
140137
err error
141138
}
142139
c := r.cache.Do("versions:"+prefix, func() interface{} {
143-
logTimer := time.AfterFunc(logFindingDelay, func() {
144-
fmt.Fprintf(os.Stderr, "go: finding versions for %s\n", r.path)
145-
})
146-
defer logTimer.Stop()
147-
148140
list, err := r.r.Versions(prefix)
149141
return cached{list, err}
150142
}).(cached)
@@ -167,11 +159,6 @@ func (r *cachingRepo) Stat(rev string) (*RevInfo, error) {
167159
return cachedInfo{info, nil}
168160
}
169161

170-
logTimer := time.AfterFunc(logFindingDelay, func() {
171-
fmt.Fprintf(os.Stderr, "go: finding %s %s\n", r.path, rev)
172-
})
173-
defer logTimer.Stop()
174-
175162
info, err = r.r.Stat(rev)
176163
if err == nil {
177164
// If we resolved, say, 1234abcde to v0.0.0-20180604122334-1234abcdef78,
@@ -199,11 +186,6 @@ func (r *cachingRepo) Stat(rev string) (*RevInfo, error) {
199186

200187
func (r *cachingRepo) Latest() (*RevInfo, error) {
201188
c := r.cache.Do("latest:", func() interface{} {
202-
logTimer := time.AfterFunc(logFindingDelay, func() {
203-
fmt.Fprintf(os.Stderr, "go: finding %s latest\n", r.path)
204-
})
205-
defer logTimer.Stop()
206-
207189
info, err := r.r.Latest()
208190

209191
// Save info for likely future Stat call.

src/cmd/go/internal/modload/import.go

+2
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ func Import(path string) (m module.Version, dir string, err error) {
269269
return module.Version{}, "", &ImportMissingError{Path: path}
270270
}
271271

272+
fmt.Fprintf(os.Stderr, "go: finding module for package %s\n", path)
273+
272274
candidates, err := QueryPackage(path, "latest", Allowed)
273275
if err != nil {
274276
if errors.Is(err, os.ErrNotExist) {

src/cmd/go/testdata/script/mod_load_badchain.txt

+2
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ go: example.com/badchain/a@v1.1.0 requires
7575
module declares its path as: badchain.example.com/c
7676
but was required as: example.com/badchain/c
7777
-- list-missing-expected --
78+
go: finding module for package example.com/badchain/c
7879
go: found example.com/badchain/c in example.com/badchain/c v1.1.0
7980
go: m/use imports
8081
example.com/badchain/c: example.com/badchain/c@v1.1.0: parsing go.mod:
8182
module declares its path as: badchain.example.com/c
8283
but was required as: example.com/badchain/c
8384
-- list-missing-test-expected --
85+
go: finding module for package example.com/badchain/c
8486
go: found example.com/badchain/c in example.com/badchain/c v1.1.0
8587
go: m/testuse tested by
8688
m/testuse.test imports

0 commit comments

Comments
 (0)