x/tools/internal/lsp: client won't receive replies after cancelled request #37159
Labels
FrozenDueToAge
gopls
Issues related to the Go language server, gopls.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
As a part of adding the LSP
DocumentHighlight
feature togovim
I noticed that it sometimes hangs when I use it in medium sized projects.In
govim
we vendor the internal lsp files from golang.org/x/tools and use them to communicate withgopls
.In the logs I see that govim successfully sends a
$cancelRequest
togopls
, and gets a response. But the request after (in this case aCodeAction
) never returns.When dumping the goroutines in
govim
I saw that requesting goroutine was waiting for a response onrchan
at https://github.com/golang/tools/blob/1ace956b0e17ff85a6f9bdf6973af28a26234113/internal/jsonrpc2/jsonrpc2.go#L175.It's a bit tricky to reproduce with my
govim
branch, so I created a quick hack in a forked version of tools, https://github.com/leitzler/tools/tree/cancel-hang-repro/repro.There are two flags for the repro,
-gopls
that specifiesgopls
binary path, and-cancel-delay
that specifies a delay inns
before theDocumentHighlight
request is cancelled. Default it is 1000ns, which seems to work fine on my machine, but must probably be changed to reproduce the issue.Too short and the client will cancel the request before it's even sent, too long and gopls will respond before the cancel occurs.
Note that according to gopls logs, it looks like the response is sent, but it never seems to reach the client.
The repro isn't beautiful but seems to work and, per discussion on Slack with @findleyr, probably enough to pinpoint the problem.
What did you expect to see?
Requests processed as usual after a cancel.
What did you see instead?
The client hangs.
The text was updated successfully, but these errors were encountered: