Skip to content

gopls: automated issue report (crash) #63700

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

Closed
opsanatoliy opened this issue Oct 23, 2023 · 12 comments
Closed

gopls: automated issue report (crash) #63700

opsanatoliy opened this issue Oct 23, 2023 · 12 comments
Assignees
Labels
FrozenDueToAge 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

@opsanatoliy
Copy link

gopls version: v0.13.2 (go1.21.0)
gopls flags:
update flags: proxy
extension version: 0.39.1
go version: 1.21.3
environment: Visual Studio Code darwin
initialization error: undefined
issue timestamp: Mon, 23 Oct 2023 12:40:27 GMT
restart history:
Mon, 23 Oct 2023 12:08:39 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x100ff9084]

goroutine 897 [running]:
golang.org/x/tools/gopls/internal/lsp/cache.localPackageKey({{0x140005245d0, 0x17}, {0x140005245d0, 0x17}, {0x140004e4ab0, 0x5}, {0x140003fe000, 0x1, 0x1}, {0x140003fe020, ...}, ...})
	  check.go:1402  0x554
golang.org/x/tools/gopls/internal/lsp/cache.(*packageHandleBuilder).buildPackageHandle(0x1400139a060, {0x10155dcc0, 0x140000e11d0}, 0x140000e0820)
	  check.go:1090  0x234
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).getPackageHandles.func2.1()
	  check.go:891  0xb0
golang.org/x/sync/errgroup.(*Group).Go.func1()
	  errgroup.go:75  0x58
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1033
	  errgroup.go:72  0x98
[Error - 14:40:21] 

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>

@adonovan adonovan self-assigned this Oct 23, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/537075 mentions this issue: go/packages: avoid classic any((*T)(nil)) != nil pitfall with Sizes

@adonovan
Copy link
Member

There are a number of overlapping things here but the primary cause is missing error checks when converting from go list output to types.Sizes (and the logic has changed but there are different errors in both the old and the new logic).

The crash can be readily reproduced (in v0.13.2 and on master) by giving a bad GOARCH:

xtools$ git checkout gopls/v0.13.2
xtools$ go build -o x ./gopls
xtools$ GOARCH=386x ./x references  ~/w/xtools/go/packages/golist.go:#5171
...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1054dcc84]

goroutine 176 [running]:
golang.org/x/tools/gopls/internal/lsp/cache.localPackageKey({{0x140005c4320, 0x44}, {0x1400062e0c0, 0x5c}, {0x0, 0x0}, {0x140006b4860, 0x1, 0x1}, {0x140006b4880, ...}, ...})
    /Users/adonovan/w/xtools/gopls/internal/lsp/cache/check.go:1402 +0x554
golang.org/x/tools/gopls/internal/lsp/cache.(*packageHandleBuilder).buildPackageHandle(0x140003704b0, {0x105a42060, 0x1400013c460}, 0x1400013c410)
    /Users/adonovan/w/xtools/gopls/internal/lsp/cache/check.go:1090 +0x234
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).getPackageHandles.func2.1()
    /Users/adonovan/w/xtools/gopls/internal/lsp/cache/check.go:891 +0xb0
golang.org/x/sync/errgroup.(*Group).Go.func1()
    /Users/adonovan/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:75 +0x58
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
    /Users/adonovan/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:72 +0x98
xtools$ 

Fix (for tip) pending. I don't intend to fix v0.13.2.

@ansaba ansaba added the gopls Issues related to the Go language server, gopls. label Oct 23, 2023
@ansaba ansaba transferred this issue from golang/vscode-go Oct 23, 2023
@ansaba ansaba added the Tools This label describes issues relating to any tools in the x/tools repository. label Oct 23, 2023
@ansaba ansaba added this to the gopls/v0.14.1 milestone Oct 23, 2023
@adonovan
Copy link
Member

Closing as a duplicate of #63701 in gopls, for which a fix is pending.

@findleyr
Copy link
Member

Hi, can you please report if you are using a GOPACKAGESDRIVER? (echo $GOPACKAGESDRIVER)?

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/537875 mentions this issue: go/internal/packagesdriver: be defensive wrt error results

@opsanatoliy
Copy link
Author

echo $GOPACKAGESDRIVER

I am not

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/537876 mentions this issue: go/packages: don't fail if GOPACKAGESDRIVER leaves Compiler/GOARCH=""

gopherbot pushed a commit to golang/tools that referenced this issue Oct 26, 2023
While investigating a bug that turned out to lie elsewhere
(#63700), we were troubled by the inconsistencies between
the pair of errors returned by functions in this package.

This change makes things more consistent.

Updates golang/go#63700

Change-Id: I926c47572b7f666327bd1dba71ace68a5591bf2f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/537875
Reviewed-by: Robert Findley <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
gopherbot pushed a commit to golang/tools that referenced this issue Oct 26, 2023
This change causes packages.Load to set TypesSizes to a fallback
value whenever the external GOPACKAGESDRIVER fails to populate
the Compiler and GOARCH fields of the response.

Fixes golang/go#63700

Change-Id: I189ae97dde04f313f79e5db39a10b4a217cd8534
Reviewed-on: https://go-review.googlesource.com/c/tools/+/537876
Reviewed-by: Robert Findley <[email protected]>
Auto-Submit: Alan Donovan <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/537877 mentions this issue: go/packages: don't fail if GOPACKAGESDRIVER leaves Compiler/GOARCH=""

gopherbot pushed a commit to golang/tools that referenced this issue Oct 26, 2023
…ER leaves Compiler/GOARCH=""

This change causes packages.Load to set TypesSizes to a fallback
value whenever the external GOPACKAGESDRIVER fails to populate
the Compiler and GOARCH fields of the response.

Fixes golang/go#63700

Change-Id: I189ae97dde04f313f79e5db39a10b4a217cd8534
Reviewed-on: https://go-review.googlesource.com/c/tools/+/537876
Reviewed-by: Robert Findley <[email protected]>
Auto-Submit: Alan Donovan <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
(cherry picked from commit ff1953b)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/537877
Reviewed-by: Alan Donovan <[email protected]>
Auto-Submit: Robert Findley <[email protected]>
@findleyr
Copy link
Member

This should be fixed in v0.14.1-pre.1 (on v0.14.0 there is a workspace error message instead of a panic).

go install golang.org/x/tools/[email protected]

Could anyone here please try that out to confirm? With your confirmation, we will release v0.14.1 tomorrow.

@bcspragu
Copy link

bcspragu commented Dec 21, 2023

I just ran into this on v0.14.2, and I am using GOPACKAGESDRIVER:

$ gopls version
golang.org/x/tools/gopls v0.14.2
    golang.org/x/tools/[email protected] h1:sIw6vjZiuQ9S7s0auUUkHlWgsCkKZFWDHmrge8LYsnc=

Cleaned up from my editor (Helix):

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xbe7dcb]

goroutine 2862 [running]:

golang.org/x/tools/gopls/internal/lsp/cache.localPackageKey({{0xc000522930, 0x21}, {0xc00046fcb0, 0x6}, {0xc00046fc78, 0x6}, {0xc003c00180, 0x1, 0x1}, {0xc003c001a0, ...}, ...})
	<home>/.local/share/go/pkg/mod/golang.org/x/tools/[email protected]/internal/lsp/cache/check.go:1402 +0x6eb
golang.org/x/tools/gopls/internal/lsp/cache.(*packageHandleBuilder).buildPackageHandle(0xc0005a2750, {0x1162f80, 0xc000b4abe0}, 0xc00044e3c0)
	<home>/.local/share/go/pkg/mod/golang.org/x/tools/[email protected]/internal/lsp/cache/check.go:1090 +0x2be
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).getPackageHandles.func2.1()
	<home>/.local/share/go/pkg/mod/golang.org/x/tools/[email protected]/internal/lsp/cache/check.go:891 +0xd7
golang.org/x/sync/errgroup.(*Group).Go.func1()
	<home>/.local/share/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:75 +0x56
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 2800
	<home>/.local/share/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:72 +0x96

Invoking editor something like:

GOPACKAGESDRIVER="$PWD/scripts/gopackagesdriver.sh" /usr/bin/hx

And scripts/gopackagesdriver.sh has:

#!/usr/bin/env bash
exec bazel run -- @io_bazel_rules_go//go/tools/gopackagesdriver "${@}"

@adonovan
Copy link
Member

Hi @bcspragu, the filename in that stack trace shows [email protected], so I suspect you are not running the executable you intended to, and the source at that line corresponds to the bug that was fixed, as mentioned above.

Please try reinstalling gopls@latest, and check the version of the gopls command on the $PATH. Do let us know if the problem recurs after that.

@bcspragu
Copy link

Oof yeah apologies for the noise, looks like I just forgot to reload my shell to pick up my $PATH changes, which would have preferred the local 0.14.2 binary over the older system-wide one I had.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

6 participants