Skip to content

gopls: automated issue report (crash) #63700

Closed
@opsanatoliy

Description

@opsanatoliy

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>

Activity

self-assigned this
on Oct 23, 2023
gopherbot

gopherbot commented on Oct 23, 2023

@gopherbot
Contributor

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

adonovan

adonovan commented on Oct 23, 2023

@adonovan
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/sync@v0.3.0/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/sync@v0.3.0/errgroup/errgroup.go:72 +0x98
xtools$ 

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

added
goplsIssues related to the Go language server, gopls.
on Oct 23, 2023
transferred this issue fromgolang/vscode-goon Oct 23, 2023
added
ToolsThis label describes issues relating to any tools in the x/tools repository.
on Oct 23, 2023
added this to the gopls/v0.14.1 milestone on Oct 23, 2023
adonovan

adonovan commented on Oct 23, 2023

@adonovan
Member

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

findleyr

findleyr commented on Oct 26, 2023

@findleyr
Member

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

gopherbot

gopherbot commented on Oct 26, 2023

@gopherbot
Contributor

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

opsanatoliy

opsanatoliy commented on Oct 26, 2023

@opsanatoliy
Author

echo $GOPACKAGESDRIVER

I am not

gopherbot

gopherbot commented on Oct 26, 2023

@gopherbot
Contributor

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

gopherbot

gopherbot commented on Oct 26, 2023

@gopherbot
Contributor

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

added a commit that references this issue on Oct 26, 2023
3b17702
findleyr

findleyr commented on Oct 26, 2023

@findleyr
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/gopls@v0.14.1-pre.1

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

bcspragu

bcspragu commented on Dec 21, 2023

@bcspragu

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/gopls@v0.14.2 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/gopls@v0.13.2/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/gopls@v0.13.2/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/gopls@v0.13.2/internal/lsp/cache/check.go:891 +0xd7
golang.org/x/sync/errgroup.(*Group).Go.func1()
	<home>/.local/share/go/pkg/mod/golang.org/x/sync@v0.3.0/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/sync@v0.3.0/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

adonovan commented on Dec 28, 2023

@adonovan
Member

Hi @bcspragu, the filename in that stack trace shows gopls@v0.13.2, 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

bcspragu commented on Dec 28, 2023

@bcspragu

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.

locked and limited conversation to collaborators on Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @ansaba@bcspragu@adonovan@gopherbot@findleyr

      Issue actions

        gopls: automated issue report (crash) · Issue #63700 · golang/go