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

LSP not responding when editor quits and sends shutdown request #20700

Closed
cngarrison opened this issue Sep 27, 2023 · 11 comments · Fixed by #28232
Closed

LSP not responding when editor quits and sends shutdown request #20700

cngarrison opened this issue Sep 27, 2023 · 11 comments · Fixed by #28232
Assignees
Labels
cli related to cli/ dir lsp related to the language server upstream Changes in upstream are required to solve these issues

Comments

@cngarrison
Copy link

When quitting my EDITOR (BBEdit), it hangs waiting for deno lsp.

I have reported the issue to BareBones. They advised that it's possibly due to LSP server not responding correctly to the application's request to shut itself down.

Does deno lsp respond to the shutdown request?

Is there a config setting for handling the shutdown request?

@nayeemrmn
Copy link
Collaborator

The shutdown handler we have just tries to acquire the global mutex it has (ensuring in-flight operations finish) and then responds with Ok(()). If it's really hanging, maybe it's because a previous request going either way is on-going. I don't think this is been a problem with other editors though. Unfortunately I can't investigate very far since BBEdit's source isn't public.

@cngarrison Does this happen with a bare minimum reproduction? E.g. open an empty ts file in a fresh directory, plus whichever method you're using to enable the Deno LSP, and try to exit.

@cngarrison
Copy link
Author

@nayeemrmn Thanks for that feedback.

I launched BBEdit with deno LSP server enabled and no documents open. I then quit BBEdit and it quit cleanly.

I launched BBEdit, opened a new project directory (file browser), created an (empty) index.ts file, then quit BBEdit. The hang returned.

The team at BareBones is very good, and I have flagged this issue with them. Please advise if there is any further testing I can help with.

@nayeemrmn
Copy link
Collaborator

When quitting my EDITOR (BBEdit), it hangs waiting for deno lsp.

I have reported the issue to BareBones. They advised that it's possibly due to LSP server not responding correctly to the application's request to shut itself down.

@sigmaSd Do you know of any quirks that might relate to this?

@lucacasonato lucacasonato added cli related to cli/ dir needs investigation requires further investigation before determining if it is an issue or not lsp related to the language server labels Sep 27, 2023
@siegel
Copy link

siegel commented Sep 27, 2023

For background (and in case it helps focus the investigation):

When stopping a language server (at application quit or for certain configuration changes), BBEdit sends a shutdown request to the server and waits for a response.

After receiving a response to shutdown, BBEdit then sends the server an exit notification.

Then, BBEdit waits for the server process to exit. This is done because some language servers actually do nothing at shutdown time, and instead do all of their cleanup (index database commits, and the like) when they receive an exit, and in some cases this can take a number of seconds. (An example of this is found in clangd .)

In the case of deno, it responds normally (and rapidly) to shutdown, but after receiving the exit notification, the deno process never terminates.

If deno has any work to do when shutting the server down (such as committing an index database, or other housekeeping), the shutdown handler is the time to do this; and the exit notification handler simply needs to terminate the server process.

Hope this helps. :-)

@sigmaSd
Copy link
Contributor

sigmaSd commented Sep 27, 2023

Its never been a problem on nvim/helix, so I don't have other informations regarding this.

@nayeemrmn
Copy link
Collaborator

nayeemrmn commented Oct 10, 2023

@siegel Is there a chance BBEdit isn't closing the LSP process's stdin?

@siegel
Copy link

siegel commented Oct 10, 2023

@siegel Is there a chance BBEdit isn't closing the LSP process's stdin?

Probably. :-) BBEdit does not explicitly close the pipes until after the server process has exited as requested.

Is there something in the LSP specification that states that the client is expected to close stdin after sending the exit notification?

@nayeemrmn
Copy link
Collaborator

Is there something in the LSP specification that states that the client is expected to close stdin after sending the exit notification?

Nope. Based on the wording at https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#exit we should exit without needing that. But given that this issue occurs specifically between Deno and BBEdit, maybe both actions should be taken

@ebkalderon Could Server::serve() be changed to break its loop on exit notifications without waiting for stdin to close, so our program can finish up as normal? Or is there something we can do currently?

@ebkalderon
Copy link

ebkalderon commented Oct 10, 2023

@nayeemrmn Certainly, this could (and should) definitely be changed. In theory, Server::serve() should already gracefully shut down when it receives an exit message, regardless of the state of stdin, but if it doesn't, then there must be a bug in the logic somewhere. Please feel free to open a bug report on the tower-lsp repo to investigate further. Thanks for bringing this to my attention, folks!

@siegel
Copy link

siegel commented Oct 10, 2023

Please feel free to open a bug report on the tower-lsp repo to investigate further. Thanks for bringing this to my attention, folks!

Done! Your #399 is it. And I appreciate you taking an interest in looking into it. :-)

@nayeemrmn nayeemrmn added upstream Changes in upstream are required to solve these issues and removed needs investigation requires further investigation before determining if it is an issue or not labels Oct 15, 2023
@sgwilym
Copy link
Contributor

sgwilym commented Dec 7, 2023

I'm experiencing the same issue in Nova with the built-in LanguageClient. Manually restarting the LSP client often causes the server to hang, and after a time a stream of The request was cancelled. messages come through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli related to cli/ dir lsp related to the language server upstream Changes in upstream are required to solve these issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants