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 in PackageStats #40224

Closed
csides opened this issue Jul 15, 2020 · 6 comments
Closed

x/tools/gopls: crash in PackageStats #40224

csides opened this issue Jul 15, 2020 · 6 comments

Comments

@csides
Copy link

@csides csides commented Jul 15, 2020

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed:

Go language server (gopls) restarts several times and crashes most of them. Occasionally it will stay alive for a few minutes (before crashing again).

Please attach the stack trace from the crash.
A window with the error message should have popped up in the lower half of your screen.
Please copy the stack trace from that window and paste it in this issue.

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

goroutine 92 [running]:
go/ast.Walk(0x1a94da0, 0xc01b8d1e80, 0x1a98f60, 0x0)
	/Users/sides/code/impira/opt/go/src/go/ast/walk.go:349 +0x25f9
go/ast.Inspect(...)
	/Users/sides/code/impira/opt/go/src/go/ast/walk.go:385
golang.org/x/tools/internal/lsp/cache.astCost(0x0, 0x17cb5e0)
	/Users/sides/code/go_tools/pkg/mod/golang.org/x/tools@v0.0.0-20200708181441-6004c8539734/internal/lsp/cache/cache.go:238 +0x97
golang.org/x/tools/internal/lsp/cache.(*Cache).PackageStats.func1(0x17f2480, 0xc0002d9150, 0x17cb420, 0xc007aaaee0)
	/Users/sides/code/go_tools/pkg/mod/golang.org/x/tools@v0.0.0-20200708181441-6004c8539734/internal/lsp/cache/cache.go:202 +0x21b
golang.org/x/tools/internal/memoize.(*Store).DebugOnlyIterate(0xc0002e9520, 0xc04fc485b0)
	/Users/sides/code/go_tools/pkg/mod/golang.org/x/tools@v0.0.0-20200708181441-6004c8539734/internal/memoize/memoize.go:184 +0x176
golang.org/x/tools/internal/lsp/cache.(*Cache).PackageStats(0xc0002e9500, 0xc037261f01, 0xc, 0x1a93600)
	/Users/sides/code/go_tools/pkg/mod/golang.org/x/tools@v0.0.0-20200708181441-6004c8539734/internal/lsp/cache/cache.go:175 +0x94
golang.org/x/tools/internal/lsp/debug.(*Instance).writeMemoryDebug(0xc0002fe000, 0x1, 0x1, 0x0, 0x0)
	/Users/sides/code/go_tools/pkg/mod/golang.org/x/tools@v0.0.0-20200708181441-6004c8539734/internal/lsp/debug/serve.go:460 +0x5df
golang.org/x/tools/internal/lsp/debug.(*Instance).MonitorMemory.func1(0xc00022cfa0, 0xc0002ca570, 0xc0002fe000, 0x1aa7e20, 0xc0002e5380)
	/Users/sides/code/go_tools/pkg/mod/golang.org/x/tools@v0.0.0-20200708181441-6004c8539734/internal/lsp/debug/serve.go:414 +0xb6
created by golang.org/x/tools/internal/lsp/debug.(*Instance).MonitorMemory
	/Users/sides/code/go_tools/pkg/mod/golang.org/x/tools@v0.0.0-20200708181441-6004c8539734/internal/lsp/debug/serve.go:406 +0x99
[Error - 8:55:20 PM] Connection to server got closed. Server will not be restarted.

Additional Information:

I believe this issue is related to PackageStats. I was poking around on the debug site mentioned here https://github.com/golang/tools/blob/master/gopls/doc/vscode.md#build-tags (localhost:6060)

When I loaded the cache tab [ http://localhost:6060/cache/1 ] (as the segfault seems to be on a cache access above):
The page had the follow text
""
Cache 1

memoize.Store entries
cache.actionHandleKey - 31
cache.packageHandleKey - 891
cache.parseKey - 4042
source.FileIdentity - 1

Per-package usage - not accurate, for guidance only
template: :7:2: executing "body" at <.PackageStats>: error calling PackageStats: runtime error: invalid memory address or nil pointer dereference
"""

  1. There's no chance this can come from the codebase I'm working on, correct? This does not seem to be related to any changes made in our repo, and reverting pretty far back in time does not fix the issue.

  2. I can provide more information if needed, but I would have to redact some pieces, so please let me know what is helpful! I tend to use moderately basic features (autocomplete, go to def/type/impl), so if there are portions of the Go extension that I can disable entirely, that might also serve as a good workaround. Thanks!

Screen Shot 2020-07-14 at 9 03 38 PM

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Jul 15, 2020

Thanks for the detailed report! To confirm, this is with gopls/v0.4.3, right? (gopls version to check.)

@heschik: Looks like this is crashing in the call to ast.Inspect. I guess we need a case to handle a nil file.

@stamblerre stamblerre transferred this issue from golang/vscode-go Jul 15, 2020
@stamblerre stamblerre changed the title gopls: automated issue report (crash) -- SegFault (SIGSEGV: segmentation violation) x/tools/gopls: crash in PackageStats Jul 15, 2020
@gopherbot gopherbot added this to the Unreleased milestone Jul 15, 2020
@stamblerre stamblerre added the NeedsFix label Jul 15, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.4.4 Jul 15, 2020
@csides
Copy link
Author

@csides csides commented Jul 15, 2020

Yup! I've updated (and reinstalled the entire extension) several times to verify.

[Info  - 9:51:06 PM] 2020/07/14 21:51:06 Build info
----------
golang.org/x/tools/gopls 0.4.3
    golang.org/x/tools/gopls@v0.4.3 h1:irz7Q+XdHNECamFKbNWKvMV2Ak6zBbwdwbZndG4545I=
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
    golang.org/x/sync@v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
    golang.org/x/tools@v0.0.0-20200708181441-6004c8539734 h1:Vc0Vx98oU/O3+qPQ36fnTT5UduS55KLh2uSGbL7mqEo=
    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
    honnef.co/go/tools@v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=
    mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=

Go info
-------
go version go1.13 darwin/amd64
@gopherbot
Copy link

@gopherbot gopherbot commented Jul 15, 2020

Change https://golang.org/cl/242797 mentions this issue: internal/lsp: handle nil pointer in PackageStats

@csides
Copy link
Author

@csides csides commented Jul 16, 2020

Thanks!
Should I be waiting for a minor version update to gopls? @stamblerre

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Jul 16, 2020

You can try it out now by installing gopls at master: GO111MODULE=on go get golang.org/x/tools/gopls@master golang.org/x/tools@master. I have to admit, I am surprised you are encountering this frequently, as it's really a corner case. Let us know if the latest version fixes it.

@csides
Copy link
Author

@csides csides commented Jul 16, 2020

I've been working with them for a few hours now. Seems to be working perfectly, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.