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: go env GOMOD tries to download newer toolchain #61455

Closed
prattmic opened this issue Jul 19, 2023 · 11 comments
Closed

cmd/go: go env GOMOD tries to download newer toolchain #61455

prattmic opened this issue Jul 19, 2023 · 11 comments
Assignees
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. GoCommand cmd/go modules
Milestone

Comments

@prattmic
Copy link
Member

If go.mod says

module example.com

go 1.22

Then running go env GOMOD with 1.21 prints:

$ go env GOMOD
go: downloading go1.22 (linux/amd64)
go: download go1.22 for linux/amd64: toolchain not available

This is a bit silly, as go env needs to determine GOMOD in order to decide to upgrade in the first place.

cc @bcmills

@dmitshur
Copy link
Contributor

dmitshur commented Jul 20, 2023

I suspect in the general case this is working as intended. The Go 1.22 language isn't finalized yet, and in theory go env GOMOD in a Go 1.22 module may do something that today's go command doesn't know about and can only produce correct behavior by doing the download.

Does it work well to do go get go@go1.21 in said module before go env GOMOD if using Go 1.21 (RC 3 or so), or using a very recent gotip that knows how to work with a 1.22 module?

Edit: I see now that there's motivation to make a special exception for go env GOMOD. Never mind. :)

@bcmills bcmills added NeedsFix The path to resolution is known, but the work has not been done. GoCommand cmd/go modules labels Jul 20, 2023
@bcmills bcmills added this to the Go1.22 milestone Jul 20, 2023
@bcmills bcmills self-assigned this Jul 20, 2023
@bcmills
Copy link
Contributor

bcmills commented Jul 20, 2023

Yep, go env GOMOD and go env GOWORK in particular have to be valid (or at least somewhat sensible), because those are what we use to determine which toolchain to upgrade to.

I suppose it's possible that we upgrade the toolchain via the go.mod and/or go.work file that we find and then the reinvoked toolchain decides to do something else instead (perhaps based on an environment variable), but a change that affects that sequence seems unlikely in the foreseeable future.

@raghvenders
Copy link
Contributor

Is this message helpful and actionable -
Screenshot 2023-11-13 172554

@bcmills bcmills modified the milestones: Go1.22, Go1.23 Feb 1, 2024
@dmitris
Copy link
Contributor

dmitris commented Feb 8, 2024

Just got bitten by this thing - the installed Go version is 1.21.7, the go.mod file has 1.22, and the CI script was trying to run go version to determine the installed Go version and see if it would need to be updated (and normally the new version of Go would be fetched and installed after that). The failure (quite cryptic, IMO) was:

go: downloading go1.22 (linux/amd64)
go: download go1.22 for linux/amd64: toolchain not available

@dmitris
Copy link
Contributor

dmitris commented Feb 8, 2024

a workaround would be to cd /tmp before executing go version. Still seems unfortunate to have to do this...

@raghvenders
Copy link
Contributor

@dmitris - I tried a fix for this with local installed go version correcting mod file. Screenshot was attached.

There is one more scenario..

Do you consider is it worth to get rid of manual version update on go workspace with go developement project shared with other go modules when ever a bump happens say 1.22 to 1.23.

For that , I am thinking of an approach is there a way to know - golang/go project do exist under workspace for respective go commands( advise user on that) and change to that version for workspace and correct other modules under that workspace if needed.

petemoore added a commit to taskcluster/community-tc-config that referenced this issue Feb 14, 2024
gerardsn added a commit to nuts-foundation/nuts-node that referenced this issue Mar 5, 2024
gerardsn added a commit to nuts-foundation/nuts-node that referenced this issue Mar 6, 2024
* upgrade to go 1.22

* reference go.mod from root

* attempt 2

* workaround for golang/go#61455
@bcmills bcmills removed their assignment Mar 14, 2024
@bcmills
Copy link
Contributor

bcmills commented Mar 14, 2024

@matloob, @samthanawalla: this is a side-effect of the recent addition of toolchain-upgrade support. I think it will have a fairly straightforward fix.

@raghvenders
Copy link
Contributor

@bcmills - I already did a fix. Shall I CL that ?

@samthanawalla
Copy link
Contributor

Just got bitten by this thing - the installed Go version is 1.21.7, the go.mod file has 1.22, and the CI script was trying to run go version to determine the installed Go version and see if it would need to be updated (and normally the new version of Go would be fetched and installed after that). The failure (quite cryptic, IMO) was:

go: downloading go1.22 (linux/amd64)
go: download go1.22 for linux/amd64: toolchain not available

@dmitris I think the error you're getting will be fixed with #66175
I think what's happening in your case is that go is trying to download the go1.22 toolchain which is not a valid toolchain.
go1.22.0 is a valid toolchain. We're changing the behavior so that it should automatically add a .0 in that case and download go1.22.0
Sorry for the frustration!

@prattmic
Regarding OP, just to confirm, the requested change is that we don't want go env GOMOD to download the newer toolchain? You only want it to display the file name of the go.mod file and not upgrade?

@prattmic
Copy link
Member Author

Regarding OP, just to confirm, the requested change is that we don't want go env GOMOD to download the newer toolchain? You only want it to display the file name of the go.mod file and not upgrade?

Yes, that was the original intention intended by this issue (Bryan suggested I file this issue). I don't personally feel strongly about the behavior, it is just a bit of an oddity given that cmd/go needs to find go.mod in order to upgrade in the first place.

@gopherbot
Copy link

Change https://go.dev/cl/581275 mentions this issue: cmd/go: go env GOMOD should not download newer toolchain

@samthanawalla samthanawalla added FixPending Issues that have a fix which has not yet been reviewed or submitted. and removed NeedsFix The path to resolution is known, but the work has not been done. labels Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. GoCommand cmd/go modules
Projects
None yet
Development

No branches or pull requests

8 participants