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

Handle requests received after shutdown message #16262

Merged
merged 2 commits into from
Feb 20, 2025
Merged

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Feb 19, 2025

Summary

This PR should help in astral-sh/ruff-vscode#676.

There are two issues that this is trying to fix all related to the way shutdown should happen as per the protocol:

  1. After the server handled the shutdown request and while waiting for the exit notification:

    If a server receives requests after a shutdown request those requests should error with InvalidRequest.

    But, we raised an error and exited. This PR fixes it by entering a loop which responds to any request during this period with InvalidRequest

  2. If the server received an exit notification but the shutdown request was never received, the server handled that by logging and exiting with success but as per the spec:

    The server should exit with success code 0 if the shutdown request has been received before; otherwise with error code 1.

    So, this PR fixes that as well by raising an error in this case.

Closes: astral-sh/ruff-vscode#676

Test Plan

I'm not sure how to go about testing this without using a mock server.

@dhruvmanila dhruvmanila added bug Something isn't working server Related to the LSP server labels Feb 19, 2025
Copy link
Contributor

github-actions bot commented Feb 19, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dhruvmanila dhruvmanila marked this pull request as ready for review February 20, 2025 09:48
Comment on lines 121 to 125
lsp::Message::Notification(lsp::Notification { method, .. })
if method == lsp_types::notification::Exit::METHOD =>
{
tracing::error!("Server received an exit notification before a shutdown request was sent. Exiting...");
Ok(true)
anyhow::bail!("Server received an exit notification before a shutdown request was sent. Exiting...");
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using anyhow::bail as a way to exit the server with failure but we could return an explicit ExitStatus instead as well

@dhruvmanila dhruvmanila enabled auto-merge (squash) February 20, 2025 11:01
@dhruvmanila dhruvmanila force-pushed the dhruv/handle-shutdown branch from c079468 to c7c6444 Compare February 20, 2025 11:06
@dhruvmanila dhruvmanila merged commit fc6b03c into main Feb 20, 2025
20 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/handle-shutdown branch February 20, 2025 11:10
dhruvmanila added a commit that referenced this pull request Feb 28, 2025
## Summary

This PR updates the ordering of changelog sections to prioritize `bug`
label such that any PRs that has that label is categorized in "Bug
fixes" section in when generating the changelog irrespective of any
other labels present on the PR.

I think this works because I've seen PRs with both `server` and `bug` in
the "Server" section instead of the "Bug fixes" section. For example,
#16262 in
https://github.com/astral-sh/ruff/releases/tag/0.9.7.

On that note, this also changes the ordering such that any PR with both
`server` and `bug` labels are in the "Bug fixes" section instead of the
"Server" section. This is in line with how "Formatter" is done. I think
it makes sense to instead prefix the entries with "Formatter:" and
"Server:" if they're bug fixes. But, I'm happy to change this such that
any PRs with `formatter` and `server` labels are always in their own
section irrespective of other labels.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server Related to the LSP server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'connection to server' error when start of vscode
2 participants