Repository navigation
Description
What happens
Retrying a failed server on demand is clearly intended: start() stops and relaunches when serverError is set, counts the attempt, shows crashed [n/20] in the LSP console and disables the definition after MAX_NUMBER_OF_RESTART_ATTEMPTS. This report is not about that.
The problem is that a retry is not only triggered by an attempt that has failed, but also by one that is still in progress. serverError stays set until the next initialize has completed, so every start() call during that window stops the attempt that is currently initialising — which has not failed — and launches yet another process. getInitializedServer() calls start() unconditionally, so any feature that asks for the server triggers it. The workspace-symbol contributor does so once per keystroke in Search Everywhere, which gave us a new server process per typed character, 2–3 processes alive at once, a shutdown timeout for each abandoned one, and several of the 20 attempts used up by one typed word although no attempt had actually failed.
Why (0.21.0, unchanged on main as of 9bdfb68)
public synchronized void start() throws LanguageServerException {
...
if (serverError != null) {
// Here the language server has been not possible
// we stop it and attempts a new restart if needed
stop();
...
numberOfRestartAttempts++;
}
...
if (this.initializeFuture == null) {
// create the connection provider, provider.start(), initialize ...stop() cancels initializeFuture and sets it to null, so the method falls through and starts a fresh process. serverError is only reset at the very end of the initialise chain:
.thenCompose(initializingContext -> initServer(rootURI, initializingContext))
.thenApply(initializingContext -> {
serverError = null;So from the moment an error is recorded until the next initialize has completed, the serverError branch runs once per caller instead of once per error: each caller kills the in-flight restart of the previous caller.
Evidence
LSP trace of one Search Everywhere session (server id bbjLanguageServer), all within the same second:
[Trace - 10:29:49] Sending request 'shutdown - (11)'. <- old connection
[Trace - 10:29:49] Sending request 'initialize - (1)'. <- process #2
[Trace - 10:29:49] Sending request 'shutdown - (2)'. <- sent to process #2, ~300 ms after its initialize
[Trace - 10:29:49] Sending request 'initialize - (1)'. <- process #3
[Trace - 10:29:49] Received response '<unknown> - (2)' in ?ms. <- process #2 answering a client that is already disposed
[Trace - 10:29:50] Received response '<unknown> - (1)' in ?ms.
Our LanguageServerFactory.createConnectionProvider was called 3 times within 270 ms in one burst, twice within 300 ms in another, and 8 times while typing one 7-letter word into Search Everywhere (4 of those within 320 ms). Each abandoned instance is only killed after the 5 s shutdown timeout, so several server processes coexist for a few seconds (each doing its own workspace indexing). Every one of these also increments numberOfRestartAttempts, so the attempt budget is consumed by typing rather than by failures.
Expected
One retry per failure. While a (re)start is already in flight, further start() calls should wait on the existing initializeFuture instead of stopping it, and only a start attempt that has itself failed should count against MAX_NUMBER_OF_RESTART_ATTEMPTS. (stop() already carries a comment about not "stopping the new process created with a new start", so protecting the new attempt seems to be the intent.)
How we got there
For transparency: the initial error was caused by a bug in our own language server. It answered cancelled requests with "result": {"code": -32800} instead of an error member, which lsp4j cannot deserialise as a workspace/symbol result. ExtendedStreamMessageProducer.fireError turned that into a listener stop and an automatic restart, as designed (#1238). We have fixed our server. This report is only about the restart being re-entered by every caller, which applies after any such error — a crashed server, or a server that cannot start. Note that this removed our trigger, not the behaviour: we are not aware of a plugin-side workaround short of disabling the workspace-symbol feature altogether (which we have not tried), so a crashed or unstartable server would still produce the per-keystroke relaunches.
Related: #1600 is about the error handler of the same initialise chain. If that handler ends up completing initializeFuture normally with null as proposed there, serverError stays set, and the re-entry described here would be what remains for a server that cannot start: a relaunch per start() call until the attempt limit disables it.
Versions: LSP4IJ 0.21.0, IntelliJ IDEA 2026.2.2 (IU-262.10315.125), Windows 10 (nothing here looks OS-specific). Seen while developing the BBj language support plugin.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
angelozerr commentedon Sep 20, 2026
Is there any chance to have a pr?
fix: keep an in-flight restart attempt alive on start()