Skip to content

cmd/go: "mod tidy" tries to require the latest version of a replacement module #70137

Closed as not planned
@developStorm

Description

Go version

go version go1.21.1 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='~/Library/Caches/go-build'
GOENV='~/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='~/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='~/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/Cellar/go/1.21.1/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/Cellar/go/1.21.1/libexec/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.21.1'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='.../zdns/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/tmp/go-build0000000=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Bump version for zmap/dns in this replace line to v1.1.63, then run go mod tidy

https://github.com/zmap/zdns/pull/468/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R20

What did you see happen?

go mod tidy
go: github.com/zmap/dns@v1.1.63 used for two different module paths (github.com/miekg/dns and github.com/zmap/dns)

What did you expect to see?

go mod tidy executes without errors.

The issue arises when tidy attempts to pull the latest version of the replacement target module (zmap/dns in this case) and includes it as an indirect requirement. When the replace target version is the latest version, the indirect require that tidy tries to add caused the above error.

Adjusting the replace directive to a non-latest version - e.g., replace github.com/miekg/dns => github.com/zmap/dns v1.1.62-zdns as what we have in the referenced PR now - allows tidy to complete without errors. However, tidy will try to introduce an indirect requirement for v1.1.63 (latest), which I believe is also undesirable, as I specifically requested a version that is not the latest in the replace directive.

I expected go mod tidy to respect whatever version specified in replace, and does not attempt to introduce the latest version as an indirect require.

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions