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/internal/lsp: client won't receive replies after cancelled request #37159

Closed
leitzler opened this issue Feb 10, 2020 · 3 comments
Closed
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

Comments

@leitzler
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version go1.13.5 darwin/amd64
github.com/golang/tools@61798d64

Does this issue reproduce with the latest release?

Yes

What did you do?

As a part of adding the LSP DocumentHighlight feature to govim 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 with gopls.

In the logs I see that govim successfully sends a $cancelRequest to gopls, and gets a response. But the request after (in this case a CodeAction) never returns.

When dumping the goroutines in govim I saw that requesting goroutine was waiting for a response on rchan 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 specifies gopls binary path, and -cancel-delay that specifies a delay in ns before the DocumentHighlight 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.

@gopherbot gopherbot added this to the Unreleased milestone Feb 10, 2020
@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 Feb 10, 2020
@myitcv myitcv added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 11, 2020
@myitcv
Copy link
Member

myitcv commented Feb 11, 2020

cc @stamblerre @findleyr

@findleyr findleyr self-assigned this Feb 11, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.4.0 Feb 11, 2020
@gopherbot
Copy link

Change https://golang.org/cl/219126 mentions this issue: internal/jsonrpc2: fix races in cancellation

@findleyr
Copy link
Contributor

@leitzler huge thanks for that repro! After debugging your program I was able to reproduce in a gopls test.

@golang golang locked and limited conversation to collaborators Feb 13, 2021
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. 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.
Projects
None yet
Development

No branches or pull requests

5 participants