Skip to content

cmd/go: get: panic: internal error: can't find reason for requirement on golang.org/x/sync@... #56494

Not planned
@icio

Description

@icio

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

$ gotip version
go version devel go1.20-e09bbae Sat Oct 29 04:48:07 2022 +0000 linux/amd64

Same result with 1.18.6, 1.19.

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/icio/.cache/go-build"
GOENV="/home/icio/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/icio/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/icio/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/icio/sdk/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/icio/sdk/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.20-e09bbae Sat Oct 29 04:48:07 2022 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/icio/go/src/github.com/icio/go-get-panic/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2460736486=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run go get -u golang.org/x/tools with go.mod:

module github.com/icio/go-get-panic

go 1.18

require (
	golang.org/x/net v0.1.0
	golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
	golang.org/x/text v0.4.0
)

What did you expect to see?

go.mod updated with latest golang.org/x/tools version.

What did you see instead?

panic: internal error: can't find reason for requirement on golang.org/x/sync@v0.0.0-20220601150217-0de741cfad7f

goroutine 1 [running]:
cmd/go/internal/modget.(*resolver).updateBuildList.func1({{0xc0000281e0, 0x11}, {0xc000032690, 0x22}})
        /home/icio/sdk/gotip/src/cmd/go/internal/modget/get.go:1760 +0xd4
cmd/go/internal/modget.(*resolver).updateBuildList(0xc00023c000, {0xb2d5d0, 0xc00002c0f8}, {0x0, 0x0, 0x0})
        /home/icio/sdk/gotip/src/cmd/go/internal/modget/get.go:1765 +0x54c
cmd/go/internal/modget.(*resolver).resolveQueries(0xc00023c000, {0xb2d5d0, 0xc00002c0f8}, {0xc000014058, 0x1, 0xc0000a3d78?})
        /home/icio/sdk/gotip/src/cmd/go/internal/modget/get.go:1243 +0x1a5
cmd/go/internal/modget.runGet({0xb2d5d0, 0xc00002c0f8}, 0xc0000285e8?, {0xc0000240f0, 0x1, 0x1})
        /home/icio/sdk/gotip/src/cmd/go/internal/modget/get.go:314 +0x408
main.invoke(0xe371a0, {0xc0000240d0, 0x3, 0x3})
        /home/icio/sdk/gotip/src/cmd/go/main.go:225 +0x3d9
main.main()
        /home/icio/sdk/gotip/src/cmd/go/main.go:179 +0x7ce

To reproduce

$ git clone https://github.com/icio/go-get-panic
Cloning into 'go-get-panic'...
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 7 (delta 1), reused 7 (delta 1), pack-reused 0
Receiving objects: 100% (7/7), done.
Resolving deltas: 100% (1/1), done.

$ cd go-get-panic

$ git checkout 2cbc2db2a48105fa2b71ec69d11b6496ba52c263

$ git rev-parse HEAD
2cbc2db2a48105fa2b71ec69d11b6496ba52c263

$ gotip version
go version devel go1.20-e09bbae Sat Oct 29 04:48:07 2022 +0000 linux/amd64

$ gotip get -u golang.org/x/tools
panic: internal error: can't find reason for requirement on golang.org/x/sync@v0.0.0-20220601150217-0de741cfad7f

goroutine 1 [running]:
cmd/go/internal/modget.(*resolver).updateBuildList.func1({{0xc0000281e0, 0x11}, {0xc000032690, 0x22}})
        /home/icio/sdk/gotip/src/cmd/go/internal/modget/get.go:1760 +0xd4
cmd/go/internal/modget.(*resolver).updateBuildList(0xc00023c000, {0xb2d5d0, 0xc00002c0f8}, {0x0, 0x0, 0x0})
        /home/icio/sdk/gotip/src/cmd/go/internal/modget/get.go:1765 +0x54c
cmd/go/internal/modget.(*resolver).resolveQueries(0xc00023c000, {0xb2d5d0, 0xc00002c0f8}, {0xc000014058, 0x1, 0xc0000a3d78?})
        /home/icio/sdk/gotip/src/cmd/go/internal/modget/get.go:1243 +0x1a5
cmd/go/internal/modget.runGet({0xb2d5d0, 0xc00002c0f8}, 0xc0000285e8?, {0xc0000240f0, 0x1, 0x1})
        /home/icio/sdk/gotip/src/cmd/go/internal/modget/get.go:314 +0x408
main.invoke(0xe371a0, {0xc0000240d0, 0x3, 0x3})
        /home/icio/sdk/gotip/src/cmd/go/main.go:225 +0x3d9
main.main()
        /home/icio/sdk/gotip/src/cmd/go/main.go:179 +0x7ce

This reproduces even if you remove the go.sum:

$ rm go.sum && gotip get -u golang.org/x/tools 2>&1 | head -1
panic: internal error: can't find reason for requirement on golang.org/x/sync@v0.0.0-20220601150217-0de741cfad7f

Uncommenting any of the requirements in go.mod and re-running go get -u golang.org/x/tools will allow go get to succeed. E.g.:

$ sed -i '/x\/net/d' go.mod  

$ git diff
diff --git a/go.mod b/go.mod
index cc0392c..05b38b1 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,6 @@ module github.com/icio/go-get-panic
 go 1.18
 
 require (
-       golang.org/x/net v0.1.0
        golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
        golang.org/x/text v0.4.0
 )

$ go get -u golang.org/x/tools
go: downgraded golang.org/x/text v0.4.0 => v0.3.7
go: upgraded golang.org/x/tools v0.1.12 => v0.2.0

In the repository where I first encountered, this I was able to fix go get -u golang.org/x/tools by removing the golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f line. Next, re-running go mod tidy reintroduces golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f to go.mod. I'm not sure if this is related, but despite having a ./go.mod at the root of the project, we also have a ./cmd/ci-test-utility/go.mod which contains golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f.

Activity

changed the title [-]affected/package: [/-] [+]go get: panic: internal error: can't find reason for requirement on golang.org/x/sync@...[/+] on Oct 31, 2022
icio

icio commented on Oct 31, 2022

@icio
Author

There's a few other people tripping over this in #47979

changed the title [-]go get: panic: internal error: can't find reason for requirement on golang.org/x/sync@...[/-] [+]cmd/go: get: panic: internal error: can't find reason for requirement on golang.org/x/sync@...[/+] on Oct 31, 2022
added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Nov 1, 2022
self-assigned this
on Nov 1, 2022
added this to the Backlog milestone on Nov 1, 2022
bcmills

bcmills commented on Nov 2, 2022

@bcmills
Contributor

I see exactly the behavior that you describe. Thank you for distilling it down to a simple reproducer!

bcmills

bcmills commented on Nov 2, 2022

@bcmills
Contributor

The conflict in this example is:

go: golang.org/x/tools@upgrade (v0.2.0) requires golang.org/x/sync@v0.0.0-20220722155255-886fb9371eb4, not (INTERNAL ERROR: no reason found for golang.org/x/sync@v0.0.0-20220601150217-0de741cfad7f)

For some reason modload.editRequirements things that golang.org/x/tools@v0.2.0 requires golang.org/x/sync@v0.0.0-20220722155255-886fb9371eb4, but the limits haven't been updated to allow that version, and with good reason: with graph pruning in effect, golang.org/x/tools@v0.2.0 doesn't depend on golang.org/x/sync at all:

~/x/tools$ git checkout v0.2.0
HEAD is now at f112c4332 go.mod: update golang.org/x dependencies

~/x/tools$ go list -m golang.org/x/sync
go: module golang.org/x/sync: not a known dependency

So I think this is another symptom of #55955.

bcmills

bcmills commented on Nov 2, 2022

@bcmills
Contributor

This arises from a dependency cycle that should be pruned out but isn't:

golang.org/x/tools@v0.2.0 golang.org/x/net@v0.1.0
golang.org/x/net@v0.1.0 golang.org/x/text@v0.4.0
golang.org/x/text@v0.4.0 golang.org/x/tools@v0.1.12
golang.org/x/tools@v0.1.12 golang.org/x/sync@v0.0.0-20220722155255-886fb9371eb4

The cycle isn't pruned because each of the module paths involved in the cycle appears explicitly in the reproducer's go.mod file, which causes those dependencies to be followed (because as far as the versionLimiter knows at that point they could become selected):
https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/modload/edit.go;l=598-603;drc=5f305ae8e5796ea3821088863a6842117c58da72

gopherbot

gopherbot commented on Nov 3, 2022

@gopherbot
Contributor

Change https://go.dev/cl/447797 mentions this issue: cmd/go: add a test that reproduces the root cause of issue #56494

84 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @josue@stapelberg@icio@anacrolix@mholt

      Issue actions

        cmd/go: get: panic: internal error: can't find reason for requirement on golang.org/x/sync@... · Issue #56494 · golang/go