Skip to content

Stopping a language server over a socket loses the exit notification and logs "Socket closed" #2012

Closed

Description

@d-biehl

When LSP4IJ stops or restarts a language server that it reaches over a socket, the exit notification often doesn't reach the language server, and the Log tab of the LSP console shows:

java.util.concurrent.CompletionException: org.eclipse.lsp4j.jsonrpc.JsonRpcException: java.net.SocketException: Socket closed
	...
Caused by: org.eclipse.lsp4j.jsonrpc.JsonRpcException: java.net.SocketException: Socket closed
	at org.eclipse.lsp4j.jsonrpc.json.StreamMessageConsumer.consume(StreamMessageConsumer.java:72)
	at com.redhat.devtools.lsp4ij.LanguageServerWrapper.lambda$start$8(LanguageServerWrapper.java:696)

A language server that LSP4IJ started is then ended without having received exit, instead of exiting by itself.

Steps

  1. Use a language server that LSP4IJ starts with SocketStreamConnectionProvider.startAndAccept, one that connects to --socket <port>. User-defined language servers with a socket transport use the same provider.
  2. Stop or restart it.
  3. The Log tab shows the exception above.

It doesn't happen every time: in PyCharm 2026.1, both of my restarts showed it; in a unit test with a language server that runs in the test, one stop in four lost exit.

Cause

LanguageServerWrapper sends outgoing messages on its message writer thread (L695-L696). shutdownAll queues exit there and calls provider.stop() right after it (L2782-L2792), and SocketStreamConnectionProvider.stop() closes the socket, often before the writer has sent exit.

Fix

Before provider.stop(), wait a short time at most until the message writer has sent the queued messages. I have a fix with a test and will open a PR.

Tested with LSP4IJ main (291a09e) in PyCharm 2026.1 on Linux. 0.21.0 has no socket transport.

AI/tooling disclosure: This issue was prepared with assistance from Claude Code. I reviewed the result manually, understand the reported problem, and verified it locally.

Activity

  1. added
    bug
    on Nov 17, 2026
  2. added this to the 0.30.0 milestone on Nov 17, 2026
  3. lagergren commented on Nov 17, 2026

    @lagergren
    Collaborator

    Agreed this is a bug and should go in.

  4. added a commit that references this issue on Nov 18, 2026
    0bdec3f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions