golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.29k stars 17.7k forks source link

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

Open sicko7947 opened 3 years ago

sicko7947 commented 3 years ago

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.
stamblerre commented 3 years ago

Thanks for the report!

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

stamblerre commented 3 years ago

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.

gopherbot commented 3 years ago

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

stamblerre commented 3 years ago

Looks like there was a bug in the fix--filed https://github.com/sergi/go-diff/issues/115.

gopherbot commented 3 years ago

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

aktau commented 3 years ago

https://github.com/golang/tools/commit/008e477491be9c24e62b3c1f48f8cbdb28fab4ae 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 commented 3 years ago

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.

aktau commented 3 years ago

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.