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: crash with invalid metadata containing blank package name #60952

Closed
Termina1 opened this issue Jun 22, 2023 · 12 comments
Closed
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

@Termina1
Copy link

Termina1 commented Jun 22, 2023

gopls version: v0.12.3 (go1.20.2)
gopls flags:
update flags: proxy
extension version: 0.39.0
go version: 1.20.2
environment: Visual Studio Code darwin
initialization error: undefined
issue timestamp: Thu, 22 Jun 2023 16:03:59 GMT
restart history:
Thu, 22 Jun 2023 16:03:41 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Hi, I just opened VSCODE after update and gopls now crashing. I'm running MacBook m2, Ventura 13.1

[Info  - 19:03:42] 2023/06/22 19:03:42 go info for /Users/vyacheslavshebanov/Work/p2p/nitro
(go dir /Users/vyacheslavshebanov/Work/p2p/nitro)
(go version go version go1.20.2 darwin/arm64)
(valid build configuration = true)
(build flags: [])
(selected go env: [GO111MODULE=, GOCACHE=/Users/vyacheslavshebanov/Library/Caches/go-build, GOFLAGS=, GOMODCACHE=/Users/vyacheslavshebanov/go/pkg/mod, GOPATH=/Users/vyacheslavshebanov/go, GOPRIVATE=, GOROOT=/opt/homebrew/Cellar/go/1.20.2/libexec, GOWORK=])


[Info  - 19:03:43] 2023/06/22 19:03:43 go/packages.Load golang/vscode-go#1
	snapshot=0
	directory=file:///Users/vyacheslavshebanov/Work/p2p/nitro
	query=[/Users/vyacheslavshebanov/Work/p2p/nitro/... builtin]
	packages=144

[Info  - 19:03:43] 2023/06/22 19:03:43 go/packages.Load golang/vscode-go#1: updating metadata for 1135 packages

[Error - 19:03:43] 2023/06/22 19:03:43 computing the shared import graph: import failed for "github.com/ethereum/go-ethereum/metrics/exp": internal error: package name is "", want "genericconf" (id="github.com/ethereum/go-ethereum/metrics/exp", path="github.com/ethereum/go-ethereum/metrics/exp") (see issue #60904)

analysis.go:455: github.com/offchainlabs/nitro/solgen/go/bridgegen: invalid export data: internal error while importing "github.com/offchainlabs/nitro/solgen/go/bridgegen" (internal error: getPackages returned wrong name  for package "github.com/offchainlabs/nitro/solgen/go/bridgegen", want contracts); please report an issue
[Info  - 19:03:43] 
true
[Info  - 19:03:43] 2023/06/22 19:03:43 go info for /Users/vyacheslavshebanov/Work/p2p/nitro
(go dir /Users/vyacheslavshebanov/Work/p2p/nitro)
(go version go version go1.20.2 darwin/arm64)
(valid build configuration = true)
(build flags: [])
(selected go env: [GO111MODULE=, GOCACHE=/Users/vyacheslavshebanov/Library/Caches/go-build, GOFLAGS=, GOMODCACHE=/Users/vyacheslavshebanov/go/pkg/mod, GOPATH=/Users/vyacheslavshebanov/go, GOPRIVATE=, GOROOT=/opt/homebrew/Cellar/go/1.20.2/libexec, GOWORK=])


[Info  - 19:03:44] 2023/06/22 19:03:44 go/packages.Load golang/vscode-go#1
	snapshot=0
	directory=file:///Users/vyacheslavshebanov/Work/p2p/nitro
	query=[/Users/vyacheslavshebanov/Work/p2p/nitro/... builtin]
	packages=144

[Info  - 19:03:44] 2023/06/22 19:03:44 go/packages.Load golang/vscode-go#1: updating metadata for 1135 packages

[Error - 19:03:44] 2023/06/22 19:03:44 computing the shared import graph: import failed for "github.com/offchainlabs/nitro/solgen/go/rollupgen": internal error: package name is "", want "staker" (id="github.com/offchainlabs/nitro/solgen/go/rollupgen", path="github.com/offchainlabs/nitro/solgen/go/rollupgen") (see issue #60904)

analysis.go:455: github.com/offchainlabs/nitro/solgen/go/bridgegen: invalid export data: internal error while importing "github.com/offchainlabs/nitro/solgen/go/bridgegen" (internal error: getPackages returned wrong name  for package "github.com/offchainlabs/nitro/solgen/go/bridgegen", want contracts); please report an issue
[Info  - 19:03:44] 
true
[Info  - 19:03:44] 2023/06/22 19:03:44 go info for /Users/vyacheslavshebanov/Work/p2p/nitro
(go dir /Users/vyacheslavshebanov/Work/p2p/nitro)
(go version go version go1.20.2 darwin/arm64)
(valid build configuration = true)
(build flags: [])
(selected go env: [GO111MODULE=, GOCACHE=/Users/vyacheslavshebanov/Library/Caches/go-build, GOFLAGS=, GOMODCACHE=/Users/vyacheslavshebanov/go/pkg/mod, GOPATH=/Users/vyacheslavshebanov/go, GOPRIVATE=, GOROOT=/opt/homebrew/Cellar/go/1.20.2/libexec, GOWORK=])


[Info  - 19:03:45] 2023/06/22 19:03:45 go/packages.Load golang/vscode-go#1
	snapshot=0
	directory=file:///Users/vyacheslavshebanov/Work/p2p/nitro
	query=[/Users/vyacheslavshebanov/Work/p2p/nitro/... builtin]
	packages=144

[Info  - 19:03:45] 2023/06/22 19:03:45 go/packages.Load golang/vscode-go#1: updating metadata for 1135 packages

[Error - 19:03:45] 2023/06/22 19:03:45 computing the shared import graph: import failed for "github.com/ethereum/go-ethereum/consensus": internal error: package name is "", want "arbos" (id="github.com/ethereum/go-ethereum/consensus", path="github.com/ethereum/go-ethereum/consensus") (see issue #60904)

analysis.go:455: github.com/offchainlabs/nitro/solgen/go/bridgegen: invalid export data: internal error while importing "github.com/offchainlabs/nitro/solgen/go/bridgegen" (internal error: getPackages returned wrong name  for package "github.com/offchainlabs/nitro/solgen/go/bridgegen", want contracts); please report an issue
[Info  - 19:03:45] 
true
[Info  - 19:03:45] 2023/06/22 19:03:45 go info for /Users/vyacheslavshebanov/Work/p2p/nitro
(go dir /Users/vyacheslavshebanov/Work/p2p/nitro)
(go version go version go1.20.2 darwin/arm64)
(valid build configuration = true)
(build flags: [])
(selected go env: [GO111MODULE=, GOCACHE=/Users/vyacheslavshebanov/Library/Caches/go-build, GOFLAGS=, GOMODCACHE=/Users/vyacheslavshebanov/go/pkg/mod, GOPATH=/Users/vyacheslavshebanov/go, GOPRIVATE=, GOROOT=/opt/homebrew/Cellar/go/1.20.2/libexec, GOWORK=])


[Info  - 19:03:45] 2023/06/22 19:03:45 go/packages.Load golang/vscode-go#1
	snapshot=0
	directory=file:///Users/vyacheslavshebanov/Work/p2p/nitro
	query=[/Users/vyacheslavshebanov/Work/p2p/nitro/... builtin]
	packages=144

[Info  - 19:03:45] 2023/06/22 19:03:45 go/packages.Load golang/vscode-go#1: updating metadata for 1135 packages

[Error - 19:03:46] 2023/06/22 19:03:46 computing the shared import graph: import failed for "github.com/offchainlabs/nitro/solgen/go/rollupgen": internal error: package name is "", want "staker" (id="github.com/offchainlabs/nitro/solgen/go/rollupgen", path="github.com/offchainlabs/nitro/solgen/go/rollupgen") (see issue #60904)

analysis.go:455: github.com/offchainlabs/nitro/solgen/go/bridgegen: invalid export data: internal error while importing "github.com/offchainlabs/nitro/solgen/go/bridgegen" (internal error: getPackages returned wrong name  for package "github.com/offchainlabs/nitro/solgen/go/bridgegen", want contracts); please report an issue
[Info  - 19:03:46] 
true
[Info  - 19:03:46] 2023/06/22 19:03:46 go info for /Users/vyacheslavshebanov/Work/p2p/nitro
(go dir /Users/vyacheslavshebanov/Work/p2p/nitro)
(go version go version go1.20.2 darwin/arm64)
(valid build configuration = true)
(build flags: [])
(selected go env: [GO111MODULE=, GOCACHE=/Users/vyacheslavshebanov/Library/Caches/go-build, GOFLAGS=, GOMODCACHE=/Users/vyacheslavshebanov/go/pkg/mod, GOPATH=/Users/vyacheslavshebanov/go, GOPRIVATE=, GOROOT=/opt/homebrew/Cellar/go/1.20.2/libexec, GOWORK=])


[Info  - 19:03:46] 2023/06/22 19:03:46 go/packages.Load golang/vscode-go#1
	snapshot=0
	directory=file:///Users/vyacheslavshebanov/Work/p2p/nitro
	query=[/Users/vyacheslavshebanov/Work/p2p/nitro/... builtin]
	packages=144

[Info  - 19:03:46] 2023/06/22 19:03:46 go/packages.Load golang/vscode-go#1: updating metadata for 1135 packages

[Error - 19:03:46] 2023/06/22 19:03:46 computing the shared import graph: import failed for "github.com/offchainlabs/nitro/solgen/go/precompilesgen": internal error: package name is "", want "headerreader" (id="github.com/offchainlabs/nitro/solgen/go/precompilesgen", path="github.com/offchainlabs/nitro/solgen/go/precompilesgen") (see issue #60904)

analysis.go:455: github.com/offchainlabs/nitro/solgen/go/bridgegen: invalid export data: internal error while importing "github.com/offchainlabs/nitro/solgen/go/bridgegen" (internal error: getPackages returned wrong name  for package "github.com/offchainlabs/nitro/solgen/go/bridgegen", want contracts); please report an issue
[Error - 19:03:47] Connection to server got closed. Server will not be restarted.
@findleyr
Copy link
Contributor

Thank you for the report. Is this an open-source repository?

@Termina1
Copy link
Author

Termina1 commented Jun 22, 2023

Yes, this is https://github.com/OffchainLabs/nitro

@findleyr
Copy link
Contributor

Not reproducing immediately for me. Does this reproduce every time for you?

Which file are you opening to get this failure?

@Termina1
Copy link
Author

Yes every time, arbnode/arbnode.go

@findleyr
Copy link
Contributor

Thanks. I don't see that file in the master branch. Are you on a different branch?

@Termina1
Copy link
Author

@findleyr
Copy link
Contributor

Sorry, I'm having a tough time getting a valid go build in that project.

In the meantime, could you run this command and let me know if it outputs anything?

go run golang.org/x/tools/go/packages/gopackages -json -test -deps ./... | grep '""'

@findleyr
Copy link
Contributor

Hrm, I do have a valid Go build now, and yet still don't reproduce. Could you also share your settings.json?

@adonovan
Copy link
Member

I can reproduce the issue locally, just from cloning the repo and running gopls check ./arbnode/node.go. As I suspected, there are Metadata records being created with an empty Name field, plus an error. Specifically, for the github.com/offchainlabs/nitro/solgen/go/precompilesgen package:

util/headerreader/header_reader.go:21:2: github.com/VictoriaMetrics/fastcache@v1.6.0 (replaced by ./fastcache): reading fastcache/go.mod: open /Users/adonovan/w/nitro/fastcache/go.mod: no such file or directory

More generally, go list for this repo produces a bunch of errors and incomplete records that gopls appears not to be sanitizing sufficiently. (I realize this repo comes with additional instructions before one is expected to be able to run go build, but it shouldn't crash gopls.)

$ go list -deps -json ./arbnode/
{
        "Dir": "/Users/adonovan/w/nitro/util/headerreader",
        "ImportPath": "github.com/offchainlabs/nitro/util/headerreader",
 ...
        "Imports": [
                ...
                "github.com/offchainlabs/nitro/solgen/go/precompilesgen",
                ...
        ],
}
...
{
        "ImportPath": "github.com/offchainlabs/nitro/solgen/go/precompilesgen",
        "DepOnly": true,
        "Incomplete": true,
        "Stale": true,
        "StaleReason": "build ID mismatch",
        "Error": {
                "ImportStack": [
                        "github.com/offchainlabs/nitro/arbnode",
                        "github.com/offchainlabs/nitro/arbnode/dataposter",
                        "github.com/offchainlabs/nitro/util/headerreader"
                ],
                "Pos": "util/headerreader/header_reader.go:21:2",
                "Err": "github.com/VictoriaMetrics/fastcache@v1.6.0 (replaced by ./fastcache): reading fastcache/go.mod: open /Users/adonovan/w/nitro/fastcache/go.mod: no such file or directory"
        }
}

@findleyr
Copy link
Contributor

Aha! Now I can reproduce as well. We're working on a fix.

@findleyr findleyr changed the title gopls: automated issue report (crash) x/tools/gopls: crash with invalid metadata containing blank package name Jun 22, 2023
@findleyr findleyr self-assigned this Jun 22, 2023
@findleyr findleyr transferred this issue from golang/vscode-go Jun 22, 2023
@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 Jun 22, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jun 22, 2023
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.12.4 Jun 22, 2023
@gopherbot
Copy link

Change https://go.dev/cl/505219 mentions this issue: gopls/internal/lsp/cache: don't record edges to invalid packages

@gopherbot
Copy link

Change https://go.dev/cl/505222 mentions this issue: gopls/internal/lsp/cache: don't record edges to invalid packages

gopherbot pushed a commit to golang/tools that referenced this issue Jun 22, 2023
The importer assumes that packages have non-empty package path and name.
Enforce this invariant when loading metadata.

Fixes golang/go#60952

Change-Id: I2f4f18e475ba306d93c8b649d19897a584e5ba19
Reviewed-on: https://go-review.googlesource.com/c/tools/+/505219
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
(cherry picked from commit c8278fe)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/505222
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jun 28, 2023
0.12.4

This is a follow up to gopls@v0.12.3 fixing a crash in the new
analysis driver, in the presence of certain invalid packages
(golang/go#60952).

0.12.3

This release fixes a couple rare but significant performance
regressions introduced in the v0.12.0 release.
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