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: panic after failed PosRange in xrefs.Index #67704

Open
perrybenyella opened this issue May 26, 2024 · 6 comments
Open

x/tools/gopls: panic after failed PosRange in xrefs.Index #67704

perrybenyella opened this issue May 26, 2024 · 6 comments
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@perrybenyella
Copy link

gopls version: v0.15.3/go1.22.1
gopls flags:
update flags: proxy
extension version: 0.41.4
environment: Visual Studio Code darwin
initialization error: undefined
issue timestamp: Sun, 26 May 2024 22:40:43 GMT
restart history:
Sun, 26 May 2024 21:36:23 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

panic: start: pos 1 is not in range [68046:88632] of file /Users/perrybenyella/Documents/GitHub/CS345/CS_345_Distributed_Systems/raft/test_test.go

goroutine 1514 [running]:
golang.org/x/tools/gopls/internal/cache/xrefs.Index.func2({0x101713c20, 0x14000e8d160})
	  xrefs.go:52  0x8c
golang.org/x/tools/gopls/internal/cache/xrefs.Index.func3({0x101713c20%3F, 0x14000e8d160})
	  xrefs.go:89  0x464
go/ast.inspector.Visit(0x140025b3400, {0x101713c20%3F, 0x14000e8d160%3F})
	  walk.go:386  0x38
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713c20, 0x14000e8d160})
	  walk.go:51  0x44
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713e50, 0x1400000f680})
	  walk.go:112  0x1d94
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713e28, 0x14000d2bac0})
	  walk.go:143  0x21e8
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713e00, 0x140004b3380})
	  walk.go:153  0x1948
go/ast.walkExprList(...)
	  walk.go:26
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713e28, 0x14000d2bb40})
	  walk.go:144  0x2208
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101714760, 0x14000d40a80})
	  walk.go:206  0x3254
go/ast.walkStmtList(...)
	  walk.go:32
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713f40, 0x14000574210})
	  walk.go:234  0x29f4
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713ea0, 0x14000574240})
	  walk.go:357  0xd90
go/ast.walkDeclList(...)
	  walk.go:38
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713ce8, 0x1400048ac80})
	  walk.go:366  0x2e14
go/ast.Inspect(...)
	  walk.go:397
golang.org/x/tools/gopls/internal/cache/xrefs.Index({0x140011712f0, 0x5, 0x140022bd600%3F}, 0x140010bf2c0, 0x140010bf320)
	  xrefs.go:57  0x130
golang.org/x/tools/gopls/internal/cache.(*syntaxPackage).xrefs.func1()
	  pkg.go:72  0x38
sync.(*Once).doSlow(0x14000582d08%3F, 0x14000583388%3F)
	  once.go:74  0x100
sync.(*Once).Do(...)
	  once.go:65
golang.org/x/tools/gopls/internal/cache.(*syntaxPackage).xrefs(0x140002bc2d0)
	  pkg.go:71  0x50
golang.org/x/tools/gopls/internal/cache.storePackageResults({0x1017189e8, 0x14001c460f0}, 0x14001164d80, 0x140011e2420)
	  check.go:582  0x80
created by golang.org/x/tools/gopls/internal/cache.(*typeCheckBatch).handleSyntaxPackage in goroutine 1420
	  check.go:570  0x5d0
gopls stats -anon { "DirStats": { "Files": 440, "TestdataFiles": 0, "GoFiles": 44, "ModFiles": 2, "Dirs": 198 }, "GOARCH": "arm64", "GOOS": "darwin", "GOPACKAGESDRIVER": "", "GOPLSCACHE": "", "GoVersion": "go1.22.1", "GoplsVersion": "v0.15.3", "InitialWorkspaceLoadDuration": "88.230458ms", "MemStats": { "HeapAlloc": 2537088, "HeapInUse": 4964352, "TotalAlloc": 11719808 }, "WorkspaceStats": { "Files": { "Total": 0, "Largest": 0, "Errs": 0 }, "Views": [ { "GoCommandVersion": "go1.22.1", "AllPackages": { "Packages": 0, "LargestPackage": 0, "CompiledGoFiles": 0, "Modules": 0 }, "WorkspacePackages": { "Packages": 0, "LargestPackage": 0, "CompiledGoFiles": 0, "Modules": 0 }, "Diagnostics": 0 } ] } }

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>

@findleyr
Copy link
Contributor

CC @adonovan this is a new one.

Transferring to the Go issue tracker.

@findleyr findleyr changed the title gopls: automated issue report (crash) x/tools/gopls: crash in xrefs.Index May 29, 2024
@findleyr findleyr transferred this issue from golang/vscode-go May 29, 2024
@findleyr findleyr added this to the gopls/v0.16.0 milestone May 29, 2024
@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 May 29, 2024
@adonovan
Copy link
Member

This is the offending line, complete with "can't fail" comment. ;-)

		nodeRange := func(n ast.Node) protocol.Range {
			rng, err := pgf.PosRange(n.Pos(), n.End())
			if err != nil {
				panic(err) // can't fail
			}
			return rng
		}

Interpreting the stack, the offending Node is the Sel identifier in a call expression x.Sel(...). I don't know how it got a bogus start pos of 1.

@adonovan
Copy link
Member

Hi @perrybenyella, do you remember how you triggered this crash while working in test_test.go? If you're able to reproduce it, that would be a great help for us trying to fix it. Thanks!

@adonovan adonovan changed the title x/tools/gopls: crash in xrefs.Index x/tools/gopls: panic after failed PosRange in xrefs.Index May 29, 2024
@ansaba ansaba added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 30, 2024
@findleyr
Copy link
Contributor

Bumping to the next milestone as this code has not changed recently, and this is our first report of this crash.

Hopefully we can get a reproducer.

@findleyr findleyr modified the milestones: gopls/v0.16.0, gopls/v0.17.0 May 31, 2024
@perrybenyella
Copy link
Author

I am not exactly sure, but I was working on a project on vscode using the live share extension with a couple of other collaborators. Then we made edits to the files (test_test.go was one of these files), and for some reason, we weren't able to save the changes we made to the files while working. Because of that, I had to restart my vs code each tim,\e it happened. This kind of happend a few times. It also seemed to be an issue that only my computer was affected by because the other collaborators did not experience it when they used their own live share links.

@findleyr
Copy link
Contributor

Absent a reproducer, I'm afraid we're unlikely to be able to fix this. Moving to the backlog.

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. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants