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: module operations fail to update go.mod when applying exclude directives #36453

Closed
perj opened this issue Jan 8, 2020 · 5 comments
Closed
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@perj
Copy link

perj commented Jan 8, 2020

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

$ go version
go version go1.13.5 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/pelle/.cache/go-build"
GOENV="/home/pelle/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/pelle/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="/home/pelle/meh/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-build319548881=/tmp/go-build -gno-record-gcc-switches"

What did you do?

mkdir bug

cd bug

cat > foo.go <<EOT
package main

import (
	_ "github.com/prometheus/client_golang/prometheus"
)

func main() {}
EOT

cat > go.mod <<EOT
module github.com/perj/bug

go 1.13

require github.com/prometheus/client_golang v1.3.0

exclude github.com/stretchr/objx v0.1.1
EOT

go build

GOPROXY=none go build && echo success

What did you expect to see?

success

What did you see instead?

go: github.com/prometheus/client_golang@v1.3.0 requires
	github.com/prometheus/common@v0.7.0 requires
	github.com/sirupsen/logrus@v1.4.2: invalid proxy URL missing scheme: none

If the exclude line is deleted from go.mod then it works as expected, using the locally cached modules instead of downloading, I verified this using strace. Notably it does seem to be using the excluded v0.1.1 version of objx, while with the exclude line it uses v0.2.0 (both exist in ~/go/pkg/mod/).

I sometimes work without a network connection and this is stopping me from compiling my program at those times.

@bcmills bcmills changed the title Go redownloads modules if exclude line exists in go.mod cmd/go: module operations fail to update go.mod when applying exclude directives Jan 8, 2020
@bcmills bcmills added modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 8, 2020
@bcmills bcmills added this to the Go1.15 milestone Jan 8, 2020
@bcmills
Copy link
Contributor

bcmills commented Jan 8, 2020

I think @jayconrod ran across this same issue recently, but I can't find an issue filed for it.

CC @matloob

@jayconrod
Copy link
Contributor

We discussed this with @rsc before the holidays. I haven't opened a proposal for this yet. I'll do so today.

The problem is that if the go command encounters an excluded version in the module graph, it must go out to the network to find the next higher version. This happens even if a higher version is required in the main go.mod. This makes the build non-deterministic: different versions may be available over time. The go command doesn't (can't?) update go.mod to avoid transitively required excluded module versions.

For now, I'd recommend using replace instead of exclude. This should result in the same set of versions being selected, but it won't go out to the network to list versions.

replace github.com/stretchr/objx v0.1.1 => github.com/stretchr/objx v0.2.0

@perj
Copy link
Author

perj commented Jan 8, 2020

Replace does indeed seem to be a valid workaround, thanks.

@ianlancetaylor
Copy link
Contributor

Are we going to do anything more with this issue? The discussion suggests that there is a workaround.

@jayconrod
Copy link
Contributor

#36465 should cover everything we need to do here, so this can be closed.

@golang golang locked and limited conversation to collaborators Jun 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants