golang/go

x/tools/gopls: crash in mapPosition computing OutgoingCalls to unsafe.Slice

ceearrashee opened this issue · 4 comments

gopls version: v0.15.3/go1.22.2
gopls flags:
update flags: proxy
extension version: 0.41.2
environment: Visual Studio Code win32
initialization error: undefined
issue timestamp: Thu, 18 Apr 2024 19:20:56 GMT
restart history:
Thu, 18 Apr 2024 18:12:44 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

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 and error messages from that window and paste it in this issue.

Failed to auto-collect gopls trace: no gopls log.

gopls stats -anon { "DirStats": { "Files": 5496, "TestdataFiles": 0, "GoFiles": 413, "ModFiles": 1, "Dirs": 383 }, "GOARCH": "amd64", "GOOS": "windows", "GOPACKAGESDRIVER": "", "GOPLSCACHE": "", "GoVersion": "go1.22.2", "GoplsVersion": "v0.15.3", "InitialWorkspaceLoadDuration": "5.9188475s", "MemStats": { "HeapAlloc": 135173400, "HeapInUse": 197967872, "TotalAlloc": 1481395568 }, "WorkspaceStats": { "Files": { "Total": 4366, "Largest": 6161825, "Errs": 0 }, "Views": [ { "GoCommandVersion": "go1.22.2", "AllPackages": { "Packages": 876, "LargestPackage": 279, "CompiledGoFiles": 4437, "Modules": 157 }, "WorkspacePackages": { "Packages": 108, "LargestPackage": 61, "CompiledGoFiles": 487, "Modules": 1 }, "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.

[Error - 22:20:56] Request textDocument/typeDefinition failed.
  Message: no type definition for SetCap
  Code: 0 
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x169d61c]

goroutine 124273 [running]:
go/token.(*File).Name(...)
	C:/Program Files/Go/src/go/token/position.go:109
golang.org/x/tools/gopls/internal/golang.mapPosition({0x1da8368, 0xc01db76090}, 0x0?, {0x1da0060, 0xc00c826000}, 0x0, 0x7)
	C:/Users/eandr/go/pkg/mod/golang.org/x/tools/gopls@v0.15.3/internal/golang/definition.go:301 +0x5c
golang.org/x/tools/gopls/internal/golang.OutgoingCalls({0x1da8368?, 0xc01b477290?}, 0xc00c826000, {0x1daad80, 0xc0082e2ea0}, {0x132?, 0x0?})
	C:/Users/eandr/go/pkg/mod/golang.org/x/tools/gopls@v0.15.3/internal/golang/call_hierarchy.go:282 +0xb32
golang.org/x/tools/gopls/internal/server.(*server).OutgoingCalls(0xc0002c4000, {0x1da83a0?, 0xc021d9b3b0?}, 0xc032136460)
	C:/Users/eandr/go/pkg/mod/golang.org/x/tools/gopls@v0.15.3/internal/server/call_hierarchy.go:58 +0x195
golang.org/x/tools/gopls/internal/protocol.serverDispatch({0x1da83a0, 0xc021d9b3b0}, {0x1dc3120, 0xc0002c4000}, 0xc01b4771d0, {0x1da8560, 0xc00b8da680})
	C:/Users/eandr/go/pkg/mod/golang.org/x/tools/gopls@v0.15.3/internal/protocol/tsserver.go:131 +0x4daa
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3({0x1da83a0, 0xc021d9b3b0}, 0xc01b4771d0, {0x1da8560, 0xc00b8da680})
	C:/Users/eandr/go/pkg/mod/golang.org/x/tools/gopls@v0.15.3/internal/protocol/protocol.go:160 +0x85
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4({0x1da83a0, 0xc021d9b3b0}, 0xc01b4771d0, {0x1da8560, 0xc00b8da680})
	C:/Users/eandr/go/pkg/mod/golang.org/x/tools/gopls@v0.15.3/internal/lsprpc/lsprpc.go:509 +0x923
golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1({0x1da83a0, 0xc021d9b3b0}, 0xc0190a6528, {0x1da8560, 0xc00b8da680})
	C:/Users/eandr/go/pkg/mod/golang.org/x/tools@v0.18.1-0.20240412183611-d92ae0781217/internal/jsonrpc2/handler.go:35 +0xc6
golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2()
	C:/Users/eandr/go/pkg/mod/golang.org/x/tools@v0.18.1-0.20240412183611-d92ae0781217/internal/jsonrpc2/handler.go:103 +0x96
created by golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2 in goroutine 124
	C:/Users/eandr/go/pkg/mod/golang.org/x/tools@v0.18.1-0.20240412183611-d92ae0781217/internal/jsonrpc2/handler.go:100 +0x1c5
[Error - 22:20:56] 

@ceearrashee Thanks for the report. It looks like browsing outgoing call hierarchy triggered the panic. Can you tell us more about when you observed this crash?

  • Were you checking the function or method named SetCap?
  • Did you notice other errors or problems before this crash? (code navigation not functioning, squiggles indicating problems in the code, etc)

@adonovan @findleyr Is this a known issue?

@hyangah no this is not a known issue, though I don't think this code has changed in a long time.

@ceearrashee is this reproducible?

I can reproduce this by computing a call hierarchy involving a call to unsafe.Slice.

These special functions cause no end of bugs.