golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.86k stars 741 forks source link

gopls: null pointer panic #3364

Closed WinnieeBear closed 5 months ago

WinnieeBear commented 5 months ago

gopls version: v0.15.3/go1.22.0 gopls flags: update flags: proxy extension version: 0.41.4 environment: Visual Studio Code linux initialization error: undefined issue timestamp: Thu, 25 Apr 2024 03:09:39 GMT restart history: Thu, 25 Apr 2024 03:07:59 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": 187, "TestdataFiles": 8, "GoFiles": 64, "ModFiles": 1, "Dirs": 100 }, "GOARCH": "amd64", "GOOS": "linux", "GOPACKAGESDRIVER": "", "GOPLSCACHE": "", "GoVersion": "go1.22.0", "GoplsVersion": "v0.15.3", "InitialWorkspaceLoadDuration": "432.017698ms", "MemStats": { "HeapAlloc": 22192736, "HeapInUse": 39763968, "TotalAlloc": 296520640 }, "WorkspaceStats": { "Files": { "Total": 1262, "Largest": 395026, "Errs": 0 }, "Views": [ { "GoCommandVersion": "go1.22.0", "AllPackages": { "Packages": 202, "LargestPackage": 161, "CompiledGoFiles": 1292, "Modules": 6 }, "WorkspacePackages": { "Packages": 23, "LargestPackage": 38, "CompiledGoFiles": 98, "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.
findleyr commented 5 months ago

Thanks for the report. Can you please share the log you see in the gopls output channel and tell us when you observed this popup (e.g. I was updating gopls, I just opened the vscode, I did refactoring, ...)? Screen Shot 2021-01-27 at 2 53 49 PM

WinnieeBear commented 5 months ago

Hi, Sorry for the late comment, since the automated bug report.

Here is the function call stack, hoping can help you debug the issue.

[Error - 9:59:30 AM] Request textDocument/semanticTokens/range failed.
  Message: semantictokens are disabled
  Code: 0 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xb8d3dc]

goroutine 45568 [running]:
go/token.(*File).Name(...)
    /usr/local/go/src/go/token/position.go:109
golang.org/x/tools/gopls/internal/golang.mapPosition({0x12952c8, 0xc00a5b7440}, 0x0?, {0x128cea0, 0xc009143e60}, 0x0, 0x7)
    /root/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({0x12952c8?, 0xc00a5b7020?}, 0xc009143e60, {0x12965a0, 0xc001082480}, {0x150?, 0x0?})
    /root/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(0xc00028a000, {0x1295300?, 0xc00aec3090?}, 0xc0049b6b40)
    /root/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({0x1295300, 0xc00aec3090}, {0x12aff40, 0xc00028a000}, 0xc00a5b6b40, {0x12954c0, 0xc009856380})
    /root/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({0x1295300, 0xc00aec3090}, 0xc00a5b6b40, {0x12954c0, 0xc009856380})
    /root/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({0x1295300, 0xc00aec3090}, 0xc00a5b6b40, {0x12954c0, 0xc009856380})
    /root/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({0x1295300, 0xc00aec3090}, 0xc00ccfb200, {0x12954c0, 0xc009856380})
    /root/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()
    /root/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 118
    /root/go/pkg/mod/golang.org/x/tools@v0.18.1-0.20240412183611-d92ae0781217/internal/jsonrpc2/handler.go:100 +0x1c5
[Error - 9:59:30 AM] 
[Error - 9:59:30 AM] Request textDocument/codeLens failed.
  Message: write EPIPE
  Code: -32099 
[Error - 9:59:30 AM] Connection to server got closed. Server will not be restarted.
[Error - 9:59:30 AM] Stopping server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 9:59:30 AM] Stopping server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
findleyr commented 5 months ago

Thank you. This is a dupe of https://go.dev/issue/66923.