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: getSnapshot called after shutdown #52543

Closed
hyangah opened this issue Apr 25, 2022 · 4 comments
Closed

x/tools/gopls: panic: getSnapshot called after shutdown #52543

hyangah opened this issue Apr 25, 2022 · 4 comments
Assignees
Labels
FrozenDueToAge 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

@hyangah
Copy link
Contributor

hyangah commented Apr 25, 2022

gopls version

built at fa7afc9

go env

GOARCH="amd64"
GOCACHE="/Users/hakim/Library/Caches/go-build"
GOENV="/Users/hakim/Library/Application Support/go/env"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hakim/go"
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVERSION="go1.18.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/hakim/projects/google/tools/go.mod"
GOWORK="/Users/hakim/projects/google/tools/go.work"
...

What did you do?

Installed the latest VSCode Go Nightly.
Changed GOOS from darwin (== GOHOSTOS) to linux using the new Go explorer UI

Screen Shot 2022-04-25 at 10 04 31 AM

What did you expect to see?

Clean restart of Gopls

(Ideally I hope to reuse the gopls instance and get all environment changes reflected through the configuration change, but vscode-go requests shutdown&restart now)

What did you see instead?

Crash. And, often vscode-go doesn't recover from this type of crash. (no restart)

Editor and settings

    "go.languageServerFlags": [ "-rpc.trace"],
    "go.toolsEnvVars": {
        "GOOS": "linux",
        "GOBIN": "",
        "GOPROXY": "https://proxy.golang.org,direct"
    }

Logs

2022/04/25 09:59:00 unknown architecture loong64
[Trace - 09:59:01.076 AM] Sending request 'initialize - (0)'.
Params: {"processId":97605,"clientInfo":{"name":"Visual Studio Code","version":"1.66.2"},"locale":"en-us","rootPath":"/Users/hakim/projects/google/tools","rootUri":"file:///Users/hakim/projects/google/tools","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional","normalizesLineEndings":true,"changeAnnotationSupport":{"groupsOnLabel":true}},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},... ,"initializationOptions":{"allExperiments":true},"trace":"off","workspaceFolders":[{"uri":"file:///Users/hakim/projects/google/tools","name":"tools"}]}


[Trace - 09:59:01.078 AM] Received response 'initialize - (0)' in 2ms.
Result: {...,"serverInfo":{"name":"gopls","version":"{\"GoVersion\":\"go1.18.1\",\"Path\":\"golang.org/x/tools/gopls\",\"Main\":{\"Path\":\"golang.org/x/tools/gopls\",\"Version\":\"(devel)\",\"Sum\":\"\",\"Replace\":null},\"Deps\":[{\"Path\":\"github.com/BurntSushi/toml\",\"Version\":\"v1.0.0\",\"Sum\":\"h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=\",\"Replace\":null},{\"Path\":\"github.com/google/go-cmp\",\"Version\":\"v0.5.7\",\"Sum\":\"h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=\",\"Replace\":null},{\"Path\":\"github.com/sergi/go-diff\",\"Version\":\"v1.1.0\",\"Sum\":\"h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\",\"Replace\":null},{\"Path\":\"golang.org/x/exp/typeparams\",\"Version\":\"v0.0.0-20220218215828-6cf2b201936e\",\"Sum\":\"h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=\",\"Replace\":null},{\"Path\":\"golang.org/x/mod\",\"Version\":\"v0.6.0-dev.0.20220419223038-86c51ed26bb4\",\"Sum\":\"h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=\",\"Replace\":null},{\"Path\":\"golang.org/x/sync\",\"Version\":\"v0.0.0-20210220032951-036812b2e83c\",\"Sum\":\"h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=\",\"Replace\":null},{\"Path\":\"golang.org/x/sys\",\"Version\":\"v0.0.0-20220209214540-3681064d5158\",\"Sum\":\"h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=\",\"Replace\":null},{\"Path\":\"golang.org/x/text\",\"Version\":\"v0.3.7\",\"Sum\":\"h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=\",\"Replace\":null},{\"Path\":\"golang.org/x/tools\",\"Version\":\"(devel)\",\"Sum\":\"\",\"Replace\":null},{\"Path\":\"golang.org/x/vuln\",\"Version\":\"v0.0.0-20220324005316-18fd808f5c7f\",\"Sum\":\"h1:9dMzk88fnONra7zrEalqkRMGa9jMGf9B5mdzhYVyI28=\",\"Replace\":null},{\"Path\":\"honnef.co/go/tools\",\"Version\":\"v0.3.0\",\"Sum\":\"h1:2LdYUZ7CIxnYgskbUZfY7FPggmqnh6shBqfWa8Tn3XU=\",\"Replace\":null},{\"Path\":\"mvdan.cc/gofumpt\",\"Version\":\"v0.3.0\",\"Sum\":\"h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=\",\"Replace\":null},{\"Path\":\"mvdan.cc/xurls/v2\",\"Version\":\"v2.4.0\",\"Sum\":\"h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=\",\"Replace\":null}],\"Settings\":[{\"Key\":\"-compiler\",\"Value\":\"gc\"},{\"Key\":\"CGO_ENABLED\",\"Value\":\"1\"},{\"Key\":\"CGO_CFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_CPPFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_CXXFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_LDFLAGS\",\"Value\":\"\"},{\"Key\":\"GOARCH\",\"Value\":\"amd64\"},{\"Key\":\"GOOS\",\"Value\":\"darwin\"},{\"Key\":\"GOAMD64\",\"Value\":\"v1\"},{\"Key\":\"vcs\",\"Value\":\"git\"},{\"Key\":\"vcs.revision\",\"Value\":\"fa7afc95f23ec9082c02a2e699ff8677470846fc\"},{\"Key\":\"vcs.time\",\"Value\":\"2022-04-22T20:11:24Z\"},{\"Key\":\"vcs.modified\",\"Value\":\"true\"}],\"Version\":\"master\"}"}}


[Trace - 09:59:01.103 AM] Sending notification 'initialized'.
Params: {}


[Trace - 09:59:01.103 AM] Received request 'window/workDoneProgress/create - (1)'.
Params: {"token":"5577006791947779410"}


[Trace - 09:59:01.118 AM] Sending response 'window/workDoneProgress/create - (1)' in 14ms.
Result: 


[Trace - 09:59:01.118 AM] Received notification '$/progress'.
Params: {"token":"5577006791947779410","value":{"kind":"begin","title":"Setting up workspace","message":"Loading packages..."}}


[Trace - 09:59:01.118 AM] Received request 'workspace/configuration - (2)'.
Params: {"items":[{"scopeUri":"file:///Users/hakim/projects/google/tools","section":"gopls"}]}


[Trace - 09:59:01.163 AM] Sending response 'workspace/configuration - (2)' in 44ms.
Result: [{"allExperiments":true}]


[Trace - 09:59:01.207 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/04/25 09:59:01 go env for /Users/hakim/projects/google/tools\n(root /Users/hakim/projects/google/tools)\n(go version go version go1.18.1 darwin/amd64)\n(valid build configuration = true)\n(build flags: [])\nGOINSECURE=\nGOROOT=/usr/local/go\nGOMOD=/Users/hakim/projects/google/tools/go.mod\nGOSUMDB=sum.golang.org\nGOMODCACHE=/Users/hakim/go/pkg/mod\nGONOPROXY=\nGOPRIVATE=\nGO111MODULE=\nGOPATH=/Users/hakim/go\nGONOSUMDB=\nGOFLAGS=\nGOPROXY=https://proxy.golang.org,direct\nGOCACHE=/Users/hakim/Library/Caches/go-build\nGOWORK=/Users/hakim/projects/google/tools/go.work\n\n"}


[Info  - 9:59:01 AM] 2022/04/25 09:59:01 go env for /Users/hakim/projects/google/tools
(root /Users/hakim/projects/google/tools)
(go version go version go1.18.1 darwin/amd64)
(valid build configuration = true)
(build flags: [])
GOINSECURE=
GOROOT=/usr/local/go
GOMOD=/Users/hakim/projects/google/tools/go.mod
GOSUMDB=sum.golang.org
GOMODCACHE=/Users/hakim/go/pkg/mod
GONOPROXY=
GOPRIVATE=
GO111MODULE=
GOPATH=/Users/hakim/go
GONOSUMDB=
GOFLAGS=
GOPROXY=https://proxy.golang.org,direct
GOCACHE=/Users/hakim/Library/Caches/go-build
GOWORK=/Users/hakim/projects/google/tools/go.work


[Trace - 09:59:03.354 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/04/25 09:59:03 go/packages.Load\n\tsnapshot=0\n\tdirectory=/Users/hakim/projects/google/tools\n\tquery=[builtin golang.org/x/tools/... golang.org/x/tools/gopls/...]\n\tpackages=593\n"}


[Info  - 9:59:03 AM] 2022/04/25 09:59:03 go/packages.Load
	snapshot=0
	directory=/Users/hakim/projects/google/tools
	query=[builtin golang.org/x/tools/... golang.org/x/tools/gopls/...]
	packages=593

[Trace - 09:59:03.857 AM] Received notification '$/progress'.
Params: {"token":"5577006791947779410","value":{"kind":"end","message":"Finished loading packages."}}


[Trace - 09:59:03.862 AM] Received request 'client/registerCapability - (3)'.
Params: {...}


[Trace - 09:59:03.901 AM] Sending response 'client/registerCapability - (3)' in 39ms.
Result: 


[Trace - 09:59:03.929 AM] Received request 'client/registerCapability - (4)'.
Params: {"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"},{"id":"textDocument/semanticTokens","method":"textDocument/semanticTokens","registerOptions":{"legend":{"tokenTypes":["namespace","type","class","enum","interface","struct","typeParameter","parameter","variable","property","enumMember","event","function","method","macro","keyword","modifier","comment","string","number","regexp","operator"],"tokenModifiers":["declaration","definition","readonly","static","deprecated","abstract","async","modification","documentation","defaultLibrary"]},"range":true,"full":true}}]}


[Trace - 09:59:03.941 AM] Sending response 'client/registerCapability - (4)' in 11ms.
Result: 


[Trace - 09:59:04.078 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/04/25 09:59:04 discovered missing identifiers: map[memRecordCycle:true pageBits:true]\n\tpackage=\"runtime\"\n"}


[Info  - 9:59:04 AM] 2022/04/25 09:59:04 discovered missing identifiers: map[memRecordCycle:true pageBits:true]
	package="runtime"

[Trace - 09:59:04.151 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/04/25 09:59:04 falling back to safe trimming due to type errors: [/usr/local/go/src/internal/buildcfg/exp.go:24:38: 2-valued (func() (goexperiment.Flags, goexperiment.Flags) literal)() (value of type (goexperiment.Flags, goexperiment.Flags)) where single value is expected] or still-missing identifiers: map[]\n\tpackage=\"internal/buildcfg\"\n"}


[Info  - 9:59:04 AM] 2022/04/25 09:59:04 falling back to safe trimming due to type errors: [/usr/local/go/src/internal/buildcfg/exp.go:24:38: 2-valued (func() (goexperiment.Flags, goexperiment.Flags) literal)() (value of type (goexperiment.Flags, goexperiment.Flags)) where single value is expected] or still-missing identifiers: map[]
	package="internal/buildcfg"

[Trace - 09:59:04.178 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/04/25 09:59:04 discovered missing identifiers: map[term:true]\n\tpackage=\"go/types\"\n"}


[Info  - 9:59:04 AM] 2022/04/25 09:59:04 discovered missing identifiers: map[term:true]
	package="go/types"

[Trace - 09:59:04.346 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/04/25 09:59:04 discovered missing identifiers: map[options:true]\n\tpackage=\"vendor/golang.org/x/text/unicode/bidi\"\n"}


[Info  - 9:59:04 AM] 2022/04/25 09:59:04 discovered missing identifiers: map[options:true]
	package="vendor/golang.org/x/text/unicode/bidi"

[Trace - 09:59:04.618 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/04/25 09:59:04 discovered missing identifiers: map[message:true]\n\tpackage=\"internal/profile\"\n"}


[Info  - 9:59:04 AM] 2022/04/25 09:59:04 discovered missing identifiers: map[message:true]
	package="internal/profile"

[Trace - 09:59:04.896 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/04/25 09:59:04 falling back to safe trimming due to type errors: [/usr/local/go/src/os/user/cgo_lookup_unix.go:195:19: int not declared by package C /usr/local/go/src/os/user/cgo_lookup_unix.go:198:27: cannot convert C._SC_GETPW_R_SIZE_MAX (untyped int constant 71) to bufferKind /usr/local/go/src/os/user/cgo_lookup_unix.go:199:27: cannot convert C._SC_GETGR_R_SIZE_MAX (untyped int constant 70) to bufferKind] or still-missing identifiers: map[]\n\tpackage=\"os/user\"\n"}


[Info  - 9:59:04 AM] 2022/04/25 09:59:04 falling back to safe trimming due to type errors: [/usr/local/go/src/os/user/cgo_lookup_unix.go:195:19: int not declared by package C /usr/local/go/src/os/user/cgo_lookup_unix.go:198:27: cannot convert C._SC_GETPW_R_SIZE_MAX (untyped int constant 71) to bufferKind /usr/local/go/src/os/user/cgo_lookup_unix.go:199:27: cannot convert C._SC_GETGR_R_SIZE_MAX (untyped int constant 70) to bufferKind] or still-missing identifiers: map[]
	package="os/user"

[Trace - 09:59:04.952 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/04/25 09:59:04 discovered missing identifiers: map[markdown:true]\n\tpackage=\"github.com/yuin/goldmark\"\n"}


[Info  - 9:59:04 AM] 2022/04/25 09:59:04 discovered missing identifiers: map[markdown:true]
	package="github.com/yuin/goldmark"

[Trace - 09:59:05.306 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/04/25 09:59:05 discovered missing identifiers: map[parser:true]\n\tpackage=\"golang.org/x/net/html\"\n"}


[Info  - 9:59:05 AM] 2022/04/25 09:59:05 discovered missing identifiers: map[parser:true]
	package="golang.org/x/net/html"

[Trace - 09:59:19.329 AM] Sending notification '$/setTrace'.
Params: {"value":"off"}


[Trace - 09:59:19.330 AM] Sending notification 'workspace/didChangeConfiguration'.
Params: {"settings":null}


[Trace - 09:59:19.330 AM] Received request 'workspace/configuration - (5)'.
Params: {"items":[{"section":"gopls"}]}


[Trace - 09:59:19.331 AM] Sending request 'shutdown - (1)'.
Params: 


[Trace - 09:59:19.333 AM] Sending response 'workspace/configuration - (5)' in 2ms.
Result: [{"allExperiments":true}]


[Trace - 09:59:19.334 AM] Received request 'workspace/configuration - (6)'.
Params: {"items":[{"scopeUri":"file:///Users/hakim/projects/google/tools","section":"gopls"}]}


[Trace - 09:59:19.335 AM] Sending response 'workspace/configuration - (6)' in 0ms.
Result: [{"allExperiments":true}]


[Trace - 09:59:19.336 AM] Received response 'shutdown - (1)' in 5ms.
Result: null


panic: getSnapshot called after shutdown

goroutine 11494 [running]:
golang.org/x/tools/internal/lsp/cache.(*View).getSnapshot(0xc0002c31e0)
	/Users/hakim/projects/google/tools/internal/lsp/cache/view.go:584 +0xff
golang.org/x/tools/internal/lsp/cache.(*View).Snapshot(0x1c5fce8?, {0xc016852bd0?, 0xc006cc3980?})
	/Users/hakim/projects/google/tools/internal/lsp/cache/view.go:577 +0x19
golang.org/x/tools/internal/lsp.(*Server).didChangeConfiguration.func1()
	/Users/hakim/projects/google/tools/internal/lsp/workspace.go:64 +0x48
created by golang.org/x/tools/internal/lsp.(*Server).didChangeConfiguration
	/Users/hakim/projects/google/tools/internal/lsp/workspace.go:63 +0x63b
@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 Apr 25, 2022
@gopherbot gopherbot added this to the Unreleased milestone Apr 25, 2022
@hyangah
Copy link
Contributor Author

hyangah commented Apr 28, 2022

It looks like this was introduced (or got worse) between gopls v0.7.3 and v0.7.4.
With v0.7.4+, I could reliably trigger this from vscode by changing configuration go.useLanguageServer on and off.

@findleyr
Copy link
Contributor

This panic was added in https://go.dev/cl/367675, which landed in v0.7.4. It is enforcing an invariant, which is apparently violated.

Thanks for your repro -- we can investigate.

@hyangah
Copy link
Contributor Author

hyangah commented Jul 14, 2022

@findleyr As you mentioned, I verified that this issue no longer exists in the gopls built from head (db8f89b)

One side-effect observed from the current vscode-go version:
there is a small window during which two gopls instances are present (one shutting down, and one starting),
so the logs in gopls (server) output channel can be confusing sometimes. But that's vscode-go problem.

@hyangah hyangah closed this as completed Jul 14, 2022
@findleyr
Copy link
Contributor

Great, thanks for verifying!

@findleyr findleyr self-assigned this Aug 8, 2022
@golang golang locked and limited conversation to collaborators Aug 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

3 participants