Repository navigation
fix: send a stopping language server nothing but exit after its shutdown request - #2151
Merged
lagergren merged 1 commit intoNov 23, 2026
Conversation
…own request LSP allows only the exit notification after the shutdown request, but a request that a feature sent to a stopping language server after its shutdown request was still written. The editor's code vision does so: it gets the language servers of the file, and sends textDocument/codeLens on another thread, which can come after the stop. The request then stayed pending until the language server answered it, or the stop cancelled it. Once the shutdown request is queued to a connection, only the exit notification and the responses to the requests of the language server are queued after it: - a request ends at once with a CancellationException, as the requests of a stopped language server do, and is neither traced nor sent; - a notification is dropped, as a $/cancelRequest already was. Fixes redhat-developer#2145
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2151 +/- ##
==========================================
- Coverage 53.22% 53.21% -0.02%
==========================================
Files 826 826
Lines 34717 34728 +11
Branches 7143 7147 +4
==========================================
+ Hits 18477 18479 +2
- Misses 13468 13477 +9
Partials 2772 2772 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
@coderabbitai review |
Action not completed
|
Collaborator
Author
|
@coderabbitai review |
Action performed
|
This was referenced Nov 23, 2026
lagergren
added a commit
that referenced
this pull request
Nov 23, 2026
…ion that it shuts down (#2162) ## What `CancelRequestAfterShutdownTest.testTheAnswerToARequestOfTheLanguageServerIsSentOnceTheShutdownIsSent`, which came with #2151, failed once on CI, on macOS 2024.2 (run [45231743923](https://github.com/redhat-developer/lsp4ij/actions/runs/45231743923), in #2160): The language server must read the answer to its request, and exit, after shutdown expected:<[shutdown, ResponseMessage, exit]> but was:<[shutdown, exit]> It's a bug in the test, not in LSP4IJ or #2151: LSP4IJ did answer the request, but over another connection. ## Cause - **A restart:** the test stops the language server while its editor is open. A stop that doesn't disable the language server lets a feature of the editor start it again, over a second connection (`start()` with the status `stopping`). The code vision does that when its first lookup of the language servers comes after the stop. - **The wrong client:** the mock language server then has two clients. The test sent `workspace/configuration` through the last of `getRemoteProxies()`, which was the new connection's, and that connection answered it. The connection that the test stops, and whose reads it checks, read only `shutdown` and `exit`. - **Reproduced:** under CPU load on macOS, with probes, main failed 2 of 2,100 runs. Each time, the second connection read the answer: [[initialize, initialized, didOpen, diagnostic, shutdown, exit], [initialize, ResponseMessage, initialized, didOpen, diagnostic, codeLens, $/cancelRequest]] With a 20 ms delay before the code vision's lookup of the language servers, 7 of 100 runs fail. Asking for the file's language servers right after the shutdown is read fails 20 of 20. ## Change - The test's connection keeps the client that it gives the language server. - The test sends the request through the client of the connection that it stops. - The test checks that the request ends with an answer: `isDone()` is also true for a request that couldn't be sent. ## Test - **With the fix:** 0 of 20 runs fail with the forced restart, and 0 of 100 with the delayed code vision (55 of them with two clients when the request was sent). - **`CancelRequestAfterShutdownTest`:** 8 tests, 0 failures, on IC 2024.2, IC 2025.3 and IU 2026.3. - **Full suite on IC 2024.2:** 2,134 tests, 0 failures, 0 errors, 7 skipped, as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2145
What
CancelRequestAfterShutdownTest.testARequestCancelledOnceTheShutdownIsSentSendsNoCancelRequestfailed on main's CI at 1e40358 (run 45186700307,Test (ubuntu-latest), IC 2024.2):Verdict: a bug in LSP4IJ, not only in the test. LSP allows only the
exitnotification aftershutdown. #2105 stopped$/cancelRequestfrom going out aftershutdown, but any other request or notification that a feature sent then was still written. Here the request came from the code vision of the test's editor.Cause
The code vision of an editor gets the language servers of its file, then sends
textDocument/codeLensfrom another thread (thenComposeAsyncinLSPCodeLensSupport). If the language server stops between the two, the request is written aftershutdown. The stop's disposal of the file supports doesn't prevent it:codeLens(params)is sent beforeCancellationSupport.executesees that its support is cancelled. Such a request then stayed pending until the language server answered it, or something cancelled it.The test doesn't switch code vision off, so the editor's background
textDocument/codeLenscan land in that window. That happens rarely: 300 runs under CPU load on macOS passed. With two temporary probes (a 1 s delay before the codeLens request, and a 2 s delay betweenshutdownandexit), main fails 10 of 10 with the CI message.Change
The messages of a connection were already queued to the message writer under one lock, which notes when
shutdownis queued (#2105). After that, onlyexitand the responses to the language server's own requests are queued:CancellationException, the same way the requests of a stopped language server end. LSP4J completes a request's future with the exception that its send throws. It isn't traced or written.$/cancelRequestalready was.shutdownchanges: the writer keeps its order, and the notifications that fix: send a language server the notifications queued before its stop ahead of its shutdown #2099 sends ahead ofshutdownare queued before it.A message is checked before it's traced and again when it's queued. If
shutdownis queued between the two checks, a message other than$/cancelRequestis traced but not written. Requests are still traced before they're queued, so that a request's trace stays ahead of its answer's.Behaviour change
A request sent to a language server after its
shutdownrequest is now cancelled at once without being sent, and no notification other thanexitis sent aftershutdown. Before, the request was written, and it stayed pending until the language server answered it or something cancelled it. A notification was written too.Callers see the same outcome as for the requests of a stopped language server:
CancellationSupporttakes theCancellationExceptionas no result, andawaitWithCheckCanceledas aProcessCanceledException. Nothing new is logged. No API changes.Test
CancelRequestAfterShutdownTestgets three tests. Each holds the shutdown answer so that the connection stays open aftershutdown:shutdownis cancelled at once, and the language server readsshutdown,exit. On main it fails: the request isn't cancelled, and it's written.shutdownisn't sent. On main it fails withbut was:<[shutdown, workspace/didChangeConfiguration, exit]>.workspace/configurationrequest that the language server sends aftershutdownis still sent. This one passes on main and with the change.Other runs:
[shutdown, textDocument/codeLens, exit]. With the change, 10 of 10 pass, and each run still sends its delayed codeLens request.CancelRequestAfterShutdownTest,ServerStopPendingRequestsTest,ServerStopPendingWorkspaceSymbolTest,LanguageServerWrapperDisposeWhileStartingTest,LanguageServerWrapperRestartTest,SelectedEditorConnectionTest,LanguageServerInstancesTest,LanguageServerManagerInstancesTest,KeepAliveDuringPendingStopTest,EditorRefreshBatchTest,ServerStartFailureTest,SocketLanguageServerTest,LanguageServerDisposeFailureTest,RejectedLanguageServerTest): 193 tests, 0 failures, 0 skipped on each of IC 2024.2, 2025.3 and IU 2026.3.