Skip to content

A language server kept alive while its last-document stop is pending is still stopped #1834

Closed

Description

@lagergren

Problem

When the last document of a language server is closed, LSP4IJ stops the server after lastDocumentDisconnectedTimeout (5 s by default), unless something keeps it alive. A keep-alive that starts during that wait doesn't keep it: the stop happens anyway. That covers a LanguageServerItem.keepAlive() lease taken during the wait, and LSPClientFeatures.keepServerAlive() starting to return true during it.

We hit this in XVM's IntelliJ plugin, whose run and debug sessions are hosted in the language server. A debug session started 0.2 s after the last Ecstasy file was closed. The server got shutdown 5.0 s after that file's didClose (16:41:03.673, then 16:41:08.677), which ended the session. The plugin now keeps the server with keepServerAlive() while a session runs, but a session started during the wait still loses it.

Cause

In LanguageServerWrapper (0.21.0, and main at e96dee9c):

  • maybeShutdown() checks keepAlive() once, when the last document disconnects. It then calls startStopTimer(), which sets the status to stopping and schedules stop() on the stop alarm.
  • The alarm's request calls stop() without checking keepAlive() again.
  • incrementKeepAlive(), which LanguageServerItem.keepAlive() calls, only increments keepAliveCounter.
  • start() and getInitializedServer() don't touch the alarm either, so a server that is used during the wait still stops, as expected without a lease.

So only connectDocument(...), which calls removeStopTimer(false), cancels a pending stop.

Expected

A server that is kept alive before the stop runs is not stopped. For example:

  • incrementKeepAlive() could cancel a pending stop, with removeStopTimer(false).
  • The alarm's request could check keepAlive() again before it calls stop(), and go back to started if it no longer applies.

The second also covers keepServerAlive(), which is a query, not an event.

Related: #1553 (the stopping status during the same wait), and #809 and #556 (keepServerAlive()).

Activity

  1. added a commit that references this issue on Nov 3, 2026
    33a35e9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions