Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: package resolution fails after selecting incorrect module when using multiple proxies #40672

Open
slon opened this issue Aug 10, 2020 · 2 comments
Labels
Milestone

Comments

@slon
Copy link
Contributor

@slon slon commented Aug 10, 2020

What version of Go are you using (go version)?

$ go version
prime@bee /t/b/bugmod> go version
go version go1.14.6 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/prime/.cache/go-build"
GOENV="/home/prime/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/prime/Code/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/bug/bugmod/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build264271803=/tmp/go-build -gno-record-gcc-switches"

What did you do?

GOPROXY environment variable may contain list of proxy URLs, that should be tried in turn. I found edge case, where multiple proxies are handled incorrectly.

prime@bee /> mkdir /tmp/bug
prime@bee /> cd /tmp/bug
prime@bee /t/bug> mkdir bugmod emptygopath proxy0 proxy1 tmpmod

prime@bee /t/bug> # Initialize first proxy.
prime@bee /t/bug> cd tmpmod
prime@bee /t/b/tmpmod> go mod init tmpmod
go: creating new go.mod: module tmpmod
prime@bee /t/b/tmpmod> env GOPATH=/tmp/bug/proxy0 go get rsc.io/quote
go: downloading rsc.io/quote v1.5.2
go: rsc.io/quote upgrade => v1.5.2
go: downloading rsc.io/sampler v1.3.0
go: downloading golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c
prime@bee /t/b/tmpmod> env GOPATH=/tmp/bug/proxy0 go mod download

prime@bee /t/b/tmpmod> # Initialize second proxy.
prime@bee /t/b/tmpmod> env GOPATH=/tmp/bug/proxy1 go get rsc.io/quote/v3
go: downloading rsc.io/quote v1.5.2
go: downloading rsc.io/quote/v3 v3.1.0
go: rsc.io/quote/v3 upgrade => v3.1.0
go: downloading rsc.io/sampler v1.3.0
go: downloading golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c
prime@bee /t/b/tmpmod> env GOPATH=/tmp/bug/proxy1 go mod download

prime@bee /t/b/tmpmod> # Trigger bug.
prime@bee /t/b/tmpmod> cd ../bugmod
prime@bee /t/b/bugmod> go mod init bugmod
prime@bee /t/b/bugmod> env GOPATH=/tmp/bug/emptygopath GOPROXY=file:///tmp/bug/proxy0/pkg/mod/cache/download,file:///tmp/bug/proxy1/pkg/mod/cache/download go get rsc.io/quote/v3
go: downloading rsc.io/quote v1.5.2
go get rsc.io/quote/v3: module rsc.io/quote@upgrade found (v1.5.2), but does not contain package rsc.io/quote/v3

What did you expect to see?

go get downloading rsc.io/quote/v3 module from the second proxy.

What did you see instead?

go get command is downloading rsc.io/quote module from the first proxy and failing with error.

@slon slon changed the title go get gets confused by multiple module proxies go get is selecting incorrect module, when using multiple proxies Aug 10, 2020
@andybons andybons changed the title go get is selecting incorrect module, when using multiple proxies cmd/go: go get is selecting incorrect module, when using multiple proxies Aug 11, 2020
@andybons andybons added this to the Unplanned milestone Aug 11, 2020
@andybons
Copy link
Member

@andybons andybons commented Aug 11, 2020

@jayconrod jayconrod changed the title cmd/go: go get is selecting incorrect module, when using multiple proxies cmd/go: package resolution fails after selecting incorrect module when using multiple proxies Aug 12, 2020
@jayconrod jayconrod modified the milestones: Unplanned, Backlog Aug 12, 2020
@jayconrod
Copy link
Contributor

@jayconrod jayconrod commented Aug 12, 2020

go get attempts to resolve each package named in its arguments to a module. In the last command, since no module in the build list provides rsc.io/quote/v3, the go command will try to download the modules rsc.io, rsc.io/quote, and rsc.io/quote/v3 from the first proxy. The first proxy has rsc.io/quote, but that module doesn't contain the package rsc.io/quote/v3.

The go command should fall back to the next proxy in this case since it didn't find the package and didn't receive a terminal error from the proxy. Instead, modload.PackageNotInModuleError is treated as a terminal error, and the go command gives up without going to the next proxy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.