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: index out of range (crash) #42927

Open
sicko7947 opened this issue Dec 1, 2020 · 8 comments
Open

x/tools/gopls: index out of range (crash) #42927

sicko7947 opened this issue Dec 1, 2020 · 8 comments
Labels
gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@sicko7947
Copy link

gopls version: v0.5.4
gopls flags:

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

panic: runtime error: index out of range [65533] with length 64335

goroutine 146 [running]:
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).DiffCharsToLines(0xc00a3728c8, 0xc002ea00c0, 0x2, 0x4, 0xc00fd04000, 0xfb4f, 0x12800, 0x13000, 0xbfe999d358b68e70, 0xc85d12f5)
	  diff.go:452  0x334
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).diffLineMode(0xc00a3728c8, 0xc00e3e6044, 0x2a026d, 0x2a07ef, 0xc00ee68044, 0x28eba0, 0x28efef, 0xbfe999d358b68e70, 0xc85d12f5, 0x12dfcc0, ...)
	  diff.go:201  0x1fb
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).diffCompute(0xc00a3728c8, 0xc00e3e6044, 0x2a026d, 0x2a07ef, 0xc00ee68044, 0x28eba0, 0x28efef, 0xa3c001, 0xbfe999d358b68e70, 0xc85d12f5, ...)
	  diff.go:188  0xa92
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).diffMainRunes(0xc00a3728c8, 0xc00e3e6000, 0x2a026e, 0x2a0800, 0xc00ee68044, 0x28eba1, 0x28efef, 0x285401, 0xbfe999d358b68e70, 0xc85d12f5, ...)
	  diff.go:119  0x3bb
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).DiffMainRunes(0xc00a3728c8, 0xc00e3e6000, 0x2a027f, 0x2a0800, 0xc00ee68000, 0x28ebb2, 0x28f000, 0xc000298701, 0x4, 0xc00a3728b8, ...)
	  diff.go:95  0xb2
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).DiffMain(...)
	  diff.go:85
golang.org/x/tools/gopls/internal/hooks.ComputeEdits(0xc0006e2f00, 0x48, 0xc00c280000, 0x2a03b7, 0xc00ccfa000, 0x28ecea, 0x2a03b7, 0x2a05b7, 0xc008940b40)
	  diff.go:14  0x18e
golang.org/x/tools/internal/lsp/source.computeFixEdits(0xe96d00, 0xc004cbc410, 0xc003ef29c0, 0xc008940b40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	  format.go:176  0x2a8
golang.org/x/tools/internal/lsp/source.computeImportEdits(0xe96d00, 0xc004cbc410, 0xc003ef29c0, 0xc008940b40, 0x0, 0x73, 0x0, 0x0, 0x0, 0xc001974d08, ...)
	  format.go:117  0x111
golang.org/x/tools/internal/lsp/source.AllImportsFixes.func1(0xc008940b40, 0xc008940b40, 0xc008940a50)
	  format.go:98  0x6f
golang.org/x/tools/internal/lsp/cache.(*importsState).runProcessEnvFunc(0xc00014d140, 0xe849a0, 0xc008940a50, 0xc004cbc410, 0xc0092a4fc0, 0x0, 0x0)
	  imports.go:103  0x4e7
golang.org/x/tools/internal/lsp/cache.(*snapshot).RunProcessEnvFunc(0xc004cbc410, 0xe849a0, 0xc008940a50, 0xc0092a4fc0, 0xc002658f60, 0x2)
	  view.go:315  0x5d
golang.org/x/tools/internal/lsp/source.AllImportsFixes(0xe849a0, 0xc008940a50, 0xe96d00, 0xc004cbc410, 0xe885e0, 0xc002658f60, 0xe96d00, 0xc004cbc410, 0xe8d700, 0xc002658f60, ...)
	  format.go:97  0x35d
golang.org/x/tools/internal/lsp.(*Server).codeAction(0xc0001bc460, 0xe848e0, 0xc0001423c0, 0xc0090ea180, 0x0, 0x0, 0x0, 0x0, 0x0)
	  code_action.go:84  0x92b
golang.org/x/tools/internal/lsp.(*Server).CodeAction(0xc0001bc460, 0xe848e0, 0xc0001423c0, 0xc0090ea180, 0xc0090ea180, 0x0, 0x0, 0x0, 0xe72320)
	  server_gen.go:12  0x54
golang.org/x/tools/internal/lsp/protocol.serverDispatch(0xe848e0, 0xc0001423c0, 0xe992c0, 0xc0001bc460, 0xc008940300, 0xe84b20, 0xc000142340, 0x0, 0xe72200, 0xc00138ef20)
	  tsserver.go:341  0x20af
golang.org/x/tools/internal/lsp/protocol.ServerHandler.func1(0xe848e0, 0xc0001423c0, 0xc008940300, 0xe84b20, 0xc000142340, 0x85d7dd9d, 0x12dfcc0)
	  protocol.go:63  0xc7
golang.org/x/tools/internal/lsp/lsprpc.handshaker.func1(0xe848e0, 0xc0001423c0, 0xc008940300, 0xe84b20, 0xc000142340, 0x0, 0x0)
	  lsprpc.go:559  0x452
golang.org/x/tools/internal/jsonrpc2.MustReplyHandler.func1(0xe848e0, 0xc0001423c0, 0xc0004494a0, 0xe84b20, 0xc000142340, 0x38668b, 0xc000296178)
	  handler.go:35  0xda
golang.org/x/tools/internal/jsonrpc2.AsyncHandler.func1.2(0xc000038480, 0xc0003c3530, 0xc000942090, 0xe848e0, 0xc0001423c0, 0xc0004494a0, 0xe84b20, 0xc000142340)
	  handler.go:103  0x8d
created by golang.org/x/tools/internal/jsonrpc2.AsyncHandler.func1
	  handler.go:100  0x179
[Error - 6:25:01 PM] 

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>

@hyangah hyangah changed the title gopls: automated issue report (crash) x/tools/gopls: index out of range (crash) Dec 1, 2020
@hyangah hyangah transferred this issue from golang/vscode-go Dec 1, 2020
@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 Dec 1, 2020
@gopherbot gopherbot added this to the Unreleased milestone Dec 1, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/vscode-go Dec 1, 2020
@stamblerre
Copy link
Contributor

Thanks for the report!

Looks like an issue in a dependency, which will hopefully be resolved soon: sergi/go-diff#89.

@stamblerre stamblerre added the NeedsFix The path to resolution is known, but the work has not been done. label Dec 1, 2020
@stamblerre stamblerre added this to Needs Triage in vscode-go: gopls by default via automation Dec 1, 2020
@stamblerre
Copy link
Contributor

We're currently waiting to find out if there will be another release of the go-diff library. If not, we will update to the latest pseudoversion.

@stamblerre stamblerre moved this from Needs Triage to In progress in vscode-go: gopls by default Dec 3, 2020
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/275439 mentions this issue: gopls: upgrade github.com/sergi/go-diff to master

@stamblerre
Copy link
Contributor

stamblerre commented Dec 4, 2020

Looks like there was a bug in the fix--filed sergi/go-diff#115.

@stamblerre stamblerre self-assigned this Dec 7, 2020
@stamblerre stamblerre moved this from In progress to Waiting for Info in vscode-go: gopls by default Dec 7, 2020
@stamblerre stamblerre removed this from Waiting for Info in vscode-go: gopls by default Dec 16, 2020
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/278775 mentions this issue: internal/lsp, gopls: recover from go-diff panics

gopherbot pushed a commit to golang/tools that referenced this issue Dec 17, 2020
This CL handles the panic in the sergi/go-diff library which has not
yet been resolved. We add an error return to the ComputeEdits function
and return an error if there is a panic. I'm not sure if this is the
best approach, but it does seem better than allowing the server to
crash.

A concern would be that the user wouldn't know why their code wasn't
being formatted, but hopefully they might look through the logs and
notice the error message. At least, other features would continue
working. The best fix will definitely be the fix for the panic, but that
is not yet available.

Threading through the error return was not pretty, but I thought it was
probably worth doing since it could be needed in other situations.

Updates golang/go#42927

Change-Id: I7f0c05eb296ef9e93b4de8ef071301cdb9dce152
Reviewed-on: https://go-review.googlesource.com/c/tools/+/278775
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
@aktau
Copy link
Contributor

aktau commented Dec 22, 2020

golang/tools@008e477 causes a compilation failure in

$ GO111MODULE=on go get -u -v golang.org/x/tools/gopls@latest
...
go/pkg/mod/golang.org/x/tools/gopls@v0.6.1/internal/hooks/hooks.go:21:24: cannot use ComputeEdits (type func(span.URI, string, string) []diff.TextEdit) as type diff.ComputeEdits in assignment
...

So I'm assuming that I'm not supposed to use @latest. I'm surprised though, it seems to all be in the same repo...

@stamblerre
Copy link
Contributor

The issue is the -u flag which upgrades dependencies to master, even though @latest does not refer to master. You can see more installation instructions here: https://github.com/golang/tools/blob/master/gopls/doc/user.md#installation. If you are trying to upgrade to master, you can run GO111MODULE=on go get golang.org/x/tools/gopls@master golang.org/x/tools@master. If you are trying to download the latest gopls release, you can run GO111MODULE=on go get golang.org/x/tools/gopls@latest.

marwan-at-work pushed a commit to marwan-at-work/tools that referenced this issue Dec 23, 2020
This CL handles the panic in the sergi/go-diff library which has not
yet been resolved. We add an error return to the ComputeEdits function
and return an error if there is a panic. I'm not sure if this is the
best approach, but it does seem better than allowing the server to
crash.

A concern would be that the user wouldn't know why their code wasn't
being formatted, but hopefully they might look through the logs and
notice the error message. At least, other features would continue
working. The best fix will definitely be the fix for the panic, but that
is not yet available.

Threading through the error return was not pretty, but I thought it was
probably worth doing since it could be needed in other situations.

Updates golang/go#42927

Change-Id: I7f0c05eb296ef9e93b4de8ef071301cdb9dce152
Reviewed-on: https://go-review.googlesource.com/c/tools/+/278775
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
@aktau
Copy link
Contributor

aktau commented Dec 24, 2020

Apologies for the noise caused by not fully grokking the installation instructions and just copying from my approach for non-module enabled packages. Thanks a lot for the help, much appreciated.

@stamblerre stamblerre added this to To Do in gopls on-deck Feb 28, 2021
@stamblerre stamblerre removed their assignment Apr 16, 2021
@stamblerre stamblerre moved this from To Do to P3 in gopls on-deck Aug 12, 2021
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. NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
No open projects
Development

No branches or pull requests

4 participants