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

x/tools/gopls: panic with patch version in go.mod file #66195

Closed
liumingmin opened this issue Mar 8, 2024 · 12 comments
Closed

x/tools/gopls: panic with patch version in go.mod file #66195

liumingmin opened this issue Mar 8, 2024 · 12 comments
Assignees
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@liumingmin
Copy link

gopls version: v0.15.1 (go1.20.13)
gopls flags:
update flags: proxy
extension version: 0.39.1
go version: 1.21.6
environment: Visual Studio Code win32
initialization error: undefined
issue timestamp: Fri, 08 Mar 2024 06:09:49 GMT
restart history:
Fri, 08 Mar 2024 02:16:19 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

panic: invalid Go version "go1.21.6" (should be something like "go1.12")

goroutine 9724 [running]:
go/types.NewChecker(0xc000bb7950%3F, 0xc006eb10c0, 0xc008a6f360, 0x7%3F)
	  check.go:237  0x24e
golang.org/x/tools/gopls/internal/cache.(*typeCheckBatch).checkPackageForImport(0xc0091a0a20, {0x111aa38, 0xc009654180}, 0xc0021f7b00)
	  check.go:702  0x4df
golang.org/x/tools/gopls/internal/cache.(*typeCheckBatch).getImportPackage(0xc0091a0a20, {0x111aa38, 0xc009654180}, {0xc000bb7950, 0x2f})
	  check.go:469  0x767
golang.org/x/tools/gopls/internal/cache.(*Snapshot).forEachPackageInternal.func1()
	  check.go:396  0x2d
golang.org/x/sync/errgroup.(*Group).Go.func1()
	  errgroup.go:78  0x64
created by golang.org/x/sync/errgroup.(*Group).Go
	  errgroup.go:75  0xa5
[Error - 10:16:36] 

OPTIONAL: If you would like to share more information, you can attach your complete gopls logs.

NOTE: THESE MAY CONTAIN SENSITIVE INFORMATION ABOUT YOUR CODEBASE.
DO NOT SHARE LOGS IF YOU ARE WORKING IN A PRIVATE REPOSITORY.

<OPTIONAL: ATTACH LOGS HERE>

@findleyr
Copy link
Member

findleyr commented Mar 8, 2024

Thank you for attaching the panicking stack. We should try to fix this for our next patch release (scheduled for Monday).

@findleyr
Copy link
Member

findleyr commented Mar 8, 2024

(I should note, this may be fixed by upgrading to Go 1.22 and reinstalling gopls).

@findleyr findleyr changed the title gopls: automated issue report (crash) x/tools/gopls: panic with patch version in go.mod file Mar 8, 2024
@adonovan adonovan transferred this issue from golang/vscode-go Mar 8, 2024
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Mar 8, 2024
@gopherbot gopherbot added this to the Unreleased milestone Mar 8, 2024
@adonovan adonovan self-assigned this Mar 8, 2024
@adonovan
Copy link
Member

adonovan commented Mar 8, 2024

go/types at go1.20 insisted on a version string of the form "go%d.%d", and would otherwise panic. gopls (since my https://go.dev/cl/557215 in January) permits strings of the form "go%d.%d.%d" as well, since later versions of go/types use the go/version.Lang operation to sanitize/normalize.

I'll change gopls to respect the stricter semantics when compiled with go1.20. I will be so happy when we can drop support for these old toolchains.

@findleyr
Copy link
Member

findleyr commented Mar 8, 2024

Indeed, that day can't come soon enough, particularly now that we've agreed on it!

Thanks for investigating.

@findleyr
Copy link
Member

findleyr commented Mar 8, 2024

@liumingmin do you have an idea of why gopls was compiled with go1.20.13, while your ambient go version is 1.21.6? gopls@v0.15.1 came out last week -- have you upgraded Go in the meantime?

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.15.2 Mar 8, 2024
@adonovan
Copy link
Member

adonovan commented Mar 8, 2024

Ah, the problem occurs only when a gopls built with go1.20 runs a go list at go1.21+. Otherwise the go1.20 list would report the go.mod file as containing a syntax error.

This is not going to fit easily into our test framework.

@findleyr
Copy link
Member

findleyr commented Mar 8, 2024

Hmm, in general I don't think we can have forward Go command compatibility. We should probably fail loudly in this scenario.

Originally I thought this was gopls compiled with go1.21.6. Given our new understanding of this problem, I think it would be OK not to fix this for gopls@v0.15.2: gopls needs to be recompiled.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/570135 mentions this issue: gopls/internal/cache: avoid go/types panic on version "go1.2.3"

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/569879 mentions this issue: [gopls-release-branch.0.15] gopls/internal/cache: avoid go/types panic on version "go1.2.3"

gopherbot pushed a commit to golang/tools that referenced this issue Mar 8, 2024
…c on version "go1.2.3"

This change fixes a gopls panic caused by giving go/types@go.1.20
a Go version string with three components, e.g. go1.2.3.

Unfortunately this is hard to write a test for, since it requires
building gopls with go1.20 and running it with a go1.21 toolchain.

Fixes golang/go#66195

Change-Id: I09257e6ded69568812b367ee80cafea30add93d3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/570135
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
(cherry picked from commit 9b64301)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/569879
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
@findleyr
Copy link
Member

findleyr commented Mar 8, 2024

This should be fixed by the next gopls prerelease (though reinstalling gopls with a more recent Go would also fix it anyway):

go install golang.org/x/tools/gopls@v0.15.2-pre.1

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/576135 mentions this issue: gopls/internal/cache: fix crash in snapshot.Analyze with patch versions

gopherbot pushed a commit to golang/tools that referenced this issue Apr 3, 2024
Fix the same crash as golang/go#66195, this time in Analyze: don't set
invalid Go versions on the types.Config.

The largest part of this change was writing a realistic test, since the
lack of a test for golang/go#66195 caused us to miss this additional
location. It was possible to create a test that worked, by using a flag
to select a go1.21 binary location.

For this test, it was required to move a couple additional integration
test preconditions into integration.Main (otherwise, the test would be
skipped due to the modified environment).

Fixes golang/go#66636

Change-Id: I24385474d4a6ebf6b7e9ae8f20948564bad3f55e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/576135
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/577301 mentions this issue: [gopls-release-branch.0.15] gopls/internal/cache: fix crash in snapshot.Analyze with patch versions

gopherbot pushed a commit to golang/tools that referenced this issue Apr 8, 2024
…ot.Analyze with patch versions

Fix the same crash as golang/go#66195, this time in Analyze: don't set
invalid Go versions on the types.Config.

The largest part of this change was writing a realistic test, since the
lack of a test for golang/go#66195 caused us to miss this additional
location. It was possible to create a test that worked, by using a flag
to select a go1.21 binary location.

For this test, it was required to move a couple additional integration
test preconditions into integration.Main (otherwise, the test would be
skipped due to the modified environment).

Updates golang/go#66636
Updates golang/go#66730

Change-Id: I24385474d4a6ebf6b7e9ae8f20948564bad3f55e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/576135
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
(cherry picked from commit c623a28)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/577301
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants