Repository navigation
fix: keep a stopped language server stopped when a start that the stop replaced runs late - #2128
Merged
lagergren merged 1 commit intoNov 23, 2026
Conversation
…p replaced runs late The task of a start runs on a pooled thread. It set the status to starting first, and only later checked whether a stop had replaced the start. When the pooled thread ran the task only after the stop had ended, the status went from stopped to starting and stayed there, since no later step of that start sets it again. The language server was stopped, but getServerStatus() and the Language Servers view showed it as starting until it was started or stopped again. It made KeepAliveDuringPendingStopTest of redhat-developer#2119 fail on IC 2024.2 (run 45082111576): after a restart and a stop right after it, the language server never showed as stopped. A probe that lets the start task run only once the stop has ended shows it on main, 3 times out of 3: startTask runs, attempt current=false status=stopped status stopped -> starting and no status change after that. The task now checks first, under the monitor that a stop replaces the start under. If the start was replaced, it ends at once, without setting the status or connecting to the language server. Behaviour change: a language server that is stopped just after a start no longer shows as starting once the stop has ended.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2128 +/- ##
==========================================
- Coverage 50.66% 50.66% -0.01%
==========================================
Files 816 816
Lines 33910 33915 +5
Branches 5290 6980 +1690
==========================================
+ Hits 17180 17182 +2
- Misses 14066 14070 +4
+ Partials 2664 2663 -1 ☔ 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
|
lagergren
added a commit
that referenced
this pull request
Nov 23, 2026
… its open documents again (#2119) Fixes #2133 #2128, whose fix `testTheReconnectionOfARestartEndsWhenTheRestartIsStopped` needs to be stable, is merged, and so is `main` into this branch (3336fea): the 10 related classes pass on it (189 tests). ## What `WatchedFilesTest.testTheWatchersOfAStoppedServerAreDropped` failed on `main` on Windows ([run 45057940746](https://github.com/redhat-developer/lsp4ij/actions/runs/45057940746)). Right after `restart()`, `getLanguageServers()` returned no language server for the open file. **Verdict: a real bug in LSP4IJ, not in the test.** The end of a keep-alive lease stopped the restarted server while it was still starting. ## Cause Since #2076, a file operation keeps its language server alive with a lease until the server is told of it: 1. The test creates a file just before the restart, so that lease ended after the restart had begun. 2. The restart's stop disconnects the open documents, and the restarted server connects them again only once it has initialized, so it had none yet. 3. The end of the lease found nothing keeping it alive, and stopped it. That cancelled its start, and the request waiting for it got nothing. A trace of a failure under load: ``` 133.585ms [EDT] restart begin 134.789ms [EDT] start NEW ATTEMPT (restart) 142.027ms [FJ] getLanguageServers matched … status=starting (the test's connect) 142.291ms [pooled 4] stop … status=starting at maybeShutdown ← decrementKeepAlive ← LanguageServerItem$1.dispose ← AbstractLSPFileListener.sendThenRelease 142.347ms initialized server=null error=CancellationException ``` In tests the stop is immediate. In the IDE it comes after `lastDocumentDisconnectedTimeout` (5 s by default), so it stops a restarted server that takes longer than that to initialize. ## Change - A restart holds off the stops for idleness from before its stop until the open documents are connected again, or until its start fails or is stopped. A start that connects again the documents of a connection that ended does so too. - A stop asked for meanwhile, as by the end of a lease, is then decided: the server stops only if nothing keeps it alive by then. A restarted server that no stop was asked for keeps running, as before, so a server that `LanguageServerManager.start()` or the console's Restart starts without an open document isn't stopped. - Leases are counted as before, once for the language server, whatever connection they were taken on. That's the contract of the public `LanguageServerItem.keepAlive()`: a lease is a demand on the server as an open document is, and an open document keeps a restarted server running. `LanguageServerItem` doesn't change. - The hold of a start that connects the documents of an ended connection again also ends when a stop replaces that start (d4efe26). The stop cancels `initializeFuture`, which then runs neither the reconnection nor the failure handler, so later stops for idleness would have waited forever. That hold exists only in this PR, so this changes nothing against `main`. - `LanguageServiceAccessor.sendDidOpenAndRefreshEditorFeatureForOpenedFiles` (package-private) returns a future that completes once each open file is connected, or its connection failed or was cancelled. The first commit of this PR tied the end of a lease to the connection it was taken on. The second one replaces that, after CodeRabbit's review: it broke the lease contract, and left a restarted server running after its last lease ended when a lease from before the restart outlived one taken after it. ## Behaviour change A lease that ends, or another reason to stop for idleness that comes, while a language server restarts no longer stops it before it has connected its open documents again. Nothing else changes for users or plugins. ## Test `KeepAliveDuringPendingStopTest`: | Test | Checks | |---|---| | `testALeaseThatEndsAsTheServerRestartsLetsItStartBeforeItStops` | The flaky test's order: the request made during the restart isn't ended by the end of the lease, and the server starts before the deferred stop for idleness stops it, as it has no document. Fails on `main`. Since 769eb34 it no longer asserts which server the request gets: in unit-test mode the deferred stop comes at once and can come before the request reads the server, which failed it on CI twice. | | `testALeaseHeldAcrossARestartKeepsTheRestartedServerRunningUntilItEnds` | CodeRabbit's order: the end of a lease taken after the restart doesn't stop the server while one from before is held; the end of that one does. | | `testALeaseTakenAfterARestartStopsTheServerWithoutDocumentWhenItEnds` | A lease on the restarted server still stops it when it ends. | | `testALeaseTakenBeforeTheServerStartsKeepsItRunningAndStopsItWhenItEnds` | A lease from before the first start. | | `testARestartedServerWithoutDocumentOrLeaseKeepsRunning` | As on `main`. | | `testTheReconnectionOfARestartEndsWhenItsStartFails`, `…WhenTheRestartIsStopped` | The hold ends when the restart's start fails or is stopped. | | `testTheReconnectionOfAStartForAnEndedConnectionEndsWhenTheStartIsStopped` | The hold of a start that connects an ended connection's documents again ends when a stop replaces it. Fails before d4efe26. | - **With a probe** that delays the lease's release 100 ms and the restarted start 300 ms, `WatchedFilesTest` fails 5 of 5 runs on `main` and passes 5 of 5 with the change. - **10 related classes** (187 tests after d4efe26: the keep-alive, watched files, move, file operation, restart and instance tests) pass on 2024.2, 2025.3 and IU 2026.3, and also merged with today's `main`. - **The full suite passes:** 1866 tests, 0 failures, 7 skipped.
This was referenced Nov 23, 2026
Closed
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.
What
KeepAliveDuringPendingStopTest.testTheReconnectionOfARestartEndsWhenTheRestartIsStoppedof #2119 failed on IC 2024.2 (run 45082111576). After a restart and a stop right after it, the language server never showed as stopped. The bug is inmain, not in #2119.Cause
The task of a start runs on a pooled thread. It set the status to
startingfirst, and only later checked whether a stop had replaced the start. When the pooled thread ran the task only after the stop had ended, the status went fromstoppedtostartingand stayed there, since no later step of that start sets it again. The server was stopped, butgetServerStatus()and the Language Servers view showed it as starting until it was started or stopped again.A probe that lets the start task run only once the stop has ended shows it on
main3 times out of 3:and no status change after that.
Change
The start task now checks first, under the monitor that a stop uses to replace the start. If the start was replaced, the task ends at once, without setting the status or connecting to the language server. It cancels the start as the same check later in the task already did; the stop has cancelled
initializeFutureby then, so the failure handler doesn't run and no error is reported.Behaviour change
A language server that is stopped just after a start no longer shows as "starting" once the stop has ended.
Test
LanguageServerWrapperRestartTest.testAStartThatAStopReplacesBeforeItsTaskRunsLeavesTheServerStoppedholds the start task back, with an application proxy, until a stop has replaced the start, then runs it. It checks that the status staysstoppedand that no connection is made. It fails onmain(expected:<stopped> but was:<starting>) and passes with the change. The existing inline-tasks helper is nowwithPooledThreadTasks.