Skip to content

Stop waiting for a server that has exited - #71

Open
regulad wants to merge 1 commit into
ltex-plus:developfrom
regulad:server-exit
Open

regulad wants to merge 1 commit into
ltex-plus:developfrom
regulad:server-exit

Conversation

@regulad

@regulad regulad commented Dec 2, 2026

Copy link
Copy Markdown

Fixes #69.

Problem

When the language server's process ends, for example because the server crashes on start, lsp-cli-plus waits forever: in initialize().get(), or in Checker.checkFile's wait for a file's diagnostics. #69 has a reproduction.

Cause

LSP4J leaves a request pending if no response comes, and nothing watched the server's process. The wait for a file's diagnostics didn't look at the process either.

Fix

  1. Requests. The new LanguageServerProcessEndpoint wraps the RemoteEndpoint that LSP4J creates and races each request against Process.onExit(). A request still pending when the process ends fails with the new LanguageServerExitedException, which carries the exit code. LspCliLanguageClient builds its server proxy over that endpoint with ServiceEndpoints.toServiceObject, so this covers initialize, textDocument/codeAction and shutdown.
  2. Diagnostics. Checker's wait for a file's diagnostics throws once the process has ended.
  3. Reporting. Both report the server's exit code, through the new message serverExitedWithExitCode. LspCliLauncher.run prints the stack trace and returns 1, as it does for other errors. changelog.xml has an entry.

Not changed

A server that stays alive but never answers still makes the client wait. Only a timeout would catch that.

Testing

  • New tests. ExitingLanguageServer exits with code 42 on start, when a document is opened, or when code actions are requested. LanguageServerExitTest covers the waits for initialize, for diagnostics and for code actions, and LspCliLauncher.run returning 1. On develop, all 4 time out after 30 s. With the fix, each passes in 3 to 5 s.
  • Full suite. mvn verify passes on JDK 21: 19 tests, ktlint, detekt and JaCoCo.
  • End to end, with ltex-cli-plus running this build:
Server Before After
cmd.exe /c exit 3 waits forever exits with code 1 within 2 s, reporting exit code 3
ltex-ls-plus 19.0.0, killed during a check waits forever exits with code 1 within 30 s, reporting exit code -1
ltex-ls-plus 18.4.0 on JDK 25, its standard error output redirected to a file waits forever exits with code 1 within 5 s

Without #68, ltex-ls-plus 18.4.0 on JDK 25 still hangs when its standard error output goes to the client: the server blocks writing its stack trace to the pipe, so its process never ends. With both changes, the client fails at once.

Once #68 is merged too, ExitingLanguageServer and #68's StderrFloodingLanguageServer can share one helper in TestTools for their command lines.


Drafted by Claude Opus 5.5 (claude-opus-5-5); reviewed by @regulad.

https://claude.ai/code/session_01Mv4cZ3LFVAJ9aG5SntwnAr

When the language server's process ended, for example because the
server crashed on start, the client waited forever: LSP4J leaves a
request pending if no response comes, and the wait for a file's
diagnostics never looked at the process.

Fail each request still pending when the process ends, through an
endpoint that wraps the one LSP4J creates, and stop waiting for
diagnostics once the process has ended. Both report the server's exit
code. Add a test server that exits on start, when a document is
opened, or when code actions are requested.

Fixes ltex-plus#69.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mv4cZ3LFVAJ9aG5SntwnAr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Waits forever when the language server exits

1 participant