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 - index out of range #35455

Closed
bmhatfield opened this issue Nov 8, 2019 · 9 comments
Closed

x/tools/gopls: crash - index out of range #35455

bmhatfield opened this issue Nov 8, 2019 · 9 comments
Assignees
Labels
Milestone

Comments

@bmhatfield
Copy link

@bmhatfield bmhatfield commented Nov 8, 2019

Hey there,

I manually keep gopls at current master to track upcoming changes.

This morning, VSCode warned me that it had stopped restarting gopls due to it crashing too many times (installed commit: f7ea15e6, go version go1.13.4 darwin/amd64):

2019/11/08 08:55:07 : go/packages.Load: no packages found for ./...
[Info  - 8:55:07 AM] 2019/11/08 08:55:07 go/packages.Load
	packages = 0
[Error - 8:55:07 AM] 2019/11/08 08:55:07 : go/packages.Load: no packages found for ./...
panic: runtime error: index out of range [0] with length 0

goroutine 14 [running]:
golang.org/x/tools/internal/lsp/cache.(*session).bestView(0xc0000bd8c0, 0xc00038c000, 0x66, 0x0, 0x0)
	/Users/bhatfield/go/src/github.com/golang/tools/internal/lsp/cache/session.go:217 +0x18f
golang.org/x/tools/internal/lsp/cache.(*session).DidOpen(0xc0000bd8c0, 0x18337c0, 0xc0001fa5a0, 0xc00038c000, 0x66, 0x0, 0xc000394c00, 0xbb6, 0xc00, 0x1601d60, ...)
	/Users/bhatfield/go/src/github.com/golang/tools/internal/lsp/cache/session.go:254 +0x2b8
golang.org/x/tools/internal/lsp.(*Server).didOpen(0xc0001ced20, 0x18337c0, 0xc0001fa5a0, 0xc000288700, 0x0, 0xc000388000)
	/Users/bhatfield/go/src/github.com/golang/tools/internal/lsp/text_synchronization.go:29 +0x15e
golang.org/x/tools/internal/lsp.(*Server).DidOpen(0xc0001ced20, 0x18337c0, 0xc0001fa5a0, 0xc000288700, 0xc000288700, 0x0)
	/Users/bhatfield/go/src/github.com/golang/tools/internal/lsp/server.go:135 +0x49
golang.org/x/tools/internal/lsp/protocol.serverHandler.Deliver(0x18484c0, 0xc0001ced20, 0x18337c0, 0xc0001fa5a0, 0xc0001cd8c0, 0xc0001fa500, 0xc00027a000)
	/Users/bhatfield/go/src/github.com/golang/tools/internal/lsp/protocol/tsserver.go:111 +0x1b66
golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc00002e660, 0xc0001cd8c0, 0xc0001ced80, 0x18337c0, 0xc0001fa5a0, 0x0, 0x0, 0xc0002000b0)
	/Users/bhatfield/go/src/github.com/golang/tools/internal/jsonrpc2/jsonrpc2.go:370 +0x170
created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
	/Users/bhatfield/go/src/github.com/golang/tools/internal/jsonrpc2/jsonrpc2.go:354 +0x877
[Error - 8:55:07 AM] Connection to server got closed. Server will not be restarted.
[Error - 8:55:07 AM] Request textDocument/documentSymbol failed.
Error: Connection got disposed.
	at Object.dispose (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/main.js:876:25)
	at Object.dispose (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-languageclient/lib/client.js:71:35)
	at LanguageClient.handleConnectionClosed (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-languageclient/lib/client.js:2153:42)
	at LanguageClient.handleConnectionClosed (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-languageclient/lib/main.js:151:15)
	at closeHandler (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-languageclient/lib/client.js:2140:18)
	at CallbackList.invoke (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at closeHandler (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/main.js:226:26)
	at CallbackList.invoke (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at StreamMessageReader.fireClose (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/messageReader.js:111:27)
	at Socket.<anonymous> (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/messageReader.js:151:46)
	at Socket.emit (events.js:205:15)
	at Pipe.<anonymous> (net.js:586:12)
[Error - 8:55:07 AM] Request textDocument/documentLink failed.
Error: Connection got disposed.
	at Object.dispose (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/main.js:876:25)
	at Object.dispose (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-languageclient/lib/client.js:71:35)
	at LanguageClient.handleConnectionClosed (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-languageclient/lib/client.js:2153:42)
	at LanguageClient.handleConnectionClosed (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-languageclient/lib/main.js:151:15)
	at closeHandler (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-languageclient/lib/client.js:2140:18)
	at CallbackList.invoke (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at closeHandler (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/main.js:226:26)
	at CallbackList.invoke (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at StreamMessageReader.fireClose (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/messageReader.js:111:27)
	at Socket.<anonymous> (/Users/bhatfield/.vscode/extensions/ms-vscode.go-0.11.9/node_modules/vscode-jsonrpc/lib/messageReader.js:151:46)
	at Socket.emit (events.js:205:15)
	at Pipe.<anonymous> (net.js:586:12)
@gopherbot gopherbot added this to the Unreleased milestone Nov 8, 2019
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 8, 2019

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

@matloob

This comment has been minimized.

Copy link
Contributor

@matloob matloob commented Nov 8, 2019

Hi, I think I have an idea where this is happening: I'm wondering if you could provide some information about the workspace you opened VSCode in: Specifically

  • Is your workspace in a module?
  • Is your workspace empty or are there packages inside of it?
@bmhatfield

This comment has been minimized.

Copy link
Author

@bmhatfield bmhatfield commented Nov 8, 2019

Sure!

The VSCode workspace features multiple directories mapped together (ie, our go monorepo, our frontend code, etc).

The go directory is in a module.

The root of the go directory contains a module, but all of the packages within it start at least two levels deep. As an example:

./go.mod
./shared/<packagename>
./services/<servicename>

I believe there are 0 packages closer than 2 directories away from the root, due to code organization reasons. All of the go tools (go build, go mod, etc) seem to work totally fine with this organization structure.

@matloob

This comment has been minimized.

Copy link
Contributor

@matloob matloob commented Nov 8, 2019

Just to make sure I understand, each of the directories in your VSCode workspace are root directories of a module (that is, each of them contain go.mod files) right?

@bmhatfield

This comment has been minimized.

Copy link
Author

@bmhatfield bmhatfield commented Nov 8, 2019

No - only one does. The rest are not go related:

Screen Shot 2019-11-08 at 11 15 20 AM

In that image, frontend-webapp and development are separate repositories, in separate folders, mapped into the workspace via VSCode's "Add Folder to Workspace..." feature. These mapped workspace directories do not exist in a common location on the underlying filesystem.

In the image, go-services is a go monorepo (subdirectories redacted) containing many different packages (200+) but everything shares just one common go.mod at the root. go-services is the only mapped workspace folder containing go-related code.

Edit: I noticed that VSCode sometimes only loads plugins/etc when working on related files. For the avoidance of doubt, I was working on .go files somewhere deep within the structure of go-services when I observed the initial vscode warning about gopls crashing.

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 8, 2019

Change https://golang.org/cl/206140 mentions this issue: go/packages: ignore no packages error from (*snapshot).load in (*session).NewView

@matloob

This comment has been minimized.

Copy link
Contributor

@matloob matloob commented Nov 8, 2019

@bmhatfield, Could you patch in https://golang.org/cl/206140 and let us know if it works?

@bmhatfield

This comment has been minimized.

Copy link
Author

@bmhatfield bmhatfield commented Nov 8, 2019

Confirmed that it's working for me locally:

[Info  - 12:40:33 PM] 2019/11/08 12:40:33 go/packages.Load
	packages = 0
[Info  - 12:40:33 PM] 2019/11/08 12:40:33 go/packages.Load
	packages = 0
[Info  - 12:40:33 PM] 2019/11/08 12:40:33 go/packages.Load
	packages = 0
[Info  - 12:40:47 PM] 2019/11/08 12:40:47 go/packages.Load
	packages = 0
[Info  - 12:40:47 PM] 2019/11/08 12:40:47 go/packages.Load
	packages = 0
[Info  - 12:40:50 PM] 2019/11/08 12:40:50 go/packages.Load
	packages = 374

(the first 5 packages = 0 line up with the 5 non-go mapped folders in my workspace, I believe)

@bmhatfield

This comment has been minimized.

Copy link
Author

@bmhatfield bmhatfield commented Nov 8, 2019

Thanks for the fast turnaround!

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.