Skip to content

fix: send the exit notification before the connection of a stopped language server closes - #2013

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
d-biehl:fix/send-exit-before-closing-the-connection
Nov 17, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
d-biehl:fix/send-exit-before-closing-the-connection

Conversation

@d-biehl

@d-biehl d-biehl commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #2012.

After the exit notification, shutdownAll now waits until the message writer has sent the messages queued so far, for a second at most, and only then stops the connection provider. A disposed language server sends no messages, so its stop doesn't wait, as before.

SocketLanguageServerTest.testAStopSendsTheExitNotificationBeforeItClosesTheConnection stops a language server that runs in the test and checks that it receives exit. Its connection provider takes 100 ms to write exit, as a writer that has other messages to send first does, so that without the change the stop loses exit every time. The test fails without the change and passes with it. Locally, on Linux, ./gradlew test passes (1,724 tests, 7 skipped). In PyCharm 2026.1, two restarts of a language server started with startAndAccept left no Socket closed in the LSP console, and the old processes exited by themselves.

Copilot AI balanced review requested due to automatic review settings November 17, 2026 16:04
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved language server shutdown reliability by ensuring the exit notification is sent before the server stops. This helps prevent incomplete shutdowns and related lifecycle errors, including when the server communicates over a socket.
    • Shutdown now proceeds without waiting indefinitely if queued messages cannot be completed.

Shutdown now waits for queued outgoing messages after sending the LSP exit notification and before stopping the provider. A socket test delays the exit write and checks that the server receives the notification before stop completes.

Changes: Socket shutdown

Layer / File(s) Summary
Drain exit notification before socket stop
src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java, src/test/java/com/redhat/devtools/lsp4ij/server/SocketLanguageServerTest.java
shutdownAll waits up to one second for queued message-writer work before the provider stops. The socket test delays the exit write, observes the notification, and checks for lifecycle errors.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: lagergren, angelozerr

Merge Risk: Minimal · up to 81bce

Stopping or restarting a socket-based language server now waits briefly for the queued exit notification to be sent before the connection closes. This should remove the intermittent "Socket closed" error on restart. The added wait is capped at one second and cannot hang shutdown. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the exit notification is now sent before the connection of a stopped language server closes. It matches the raw summary, which describes waiting for queued messages af…
Description check Passed The description is directly related to the changeset. It explains that shutdownAll waits for queued messages after the exit notification, for at most one second, before stopping the provider. It also …
Linked Issues check Passed Issue #2012 requires that, before provider.stop(), the stop waits a short time at most for the message writer to send queued messages, so that the exit notification reaches a socket language server. T…
Out of Scope Changes check Passed The PR changes two files: LanguageServerWrapper.java (about +22 lines, in shutdownAll) and SocketLanguageServerTest.java (about +124 lines, a new test with a delaying provider and supporting imports).…
Full details: Title check

Explanation

The title names the main change: the exit notification is now sent before the connection of a stopped language server closes. It matches the raw summary, which describes waiting for queued messages after the exit notification and before stopping the provider. The title uses the 'fix:' prefix and is one sentence, though at 89 characters it is slightly long.

Full details: Description check

Explanation

The description is directly related to the changeset. It explains that shutdownAll waits for queued messages after the exit notification, for at most one second, before stopping the provider. It also describes the new SocketLanguageServerTest, its 100 ms delayed writer, and the verification steps. It links issue #2012.

Full details: Linked Issues check

Explanation

Issue #2012 requires that, before provider.stop(), the stop waits a short time at most for the message writer to send queued messages, so that the exit notification reaches a socket language server. The PR summary states that shutdownAll now waits after queuing exit and before canceling the launcher or stopping the provider. The wait lasts at most one second, is skipped for a disposed wrapper, and treats interruption, execution failure, timeout, and rejection as non-fatal. The change sits in the shared shutdownAll path, so it covers startAndAccept and user-defined socket servers. SocketLanguageServerTest.testAStopSendsTheExitNotificationBeforeItClosesTheConnection adds an automated test in which the provider delays writing exit by 100 ms. The PR description reports that this test fails without the change and passes with it. Limitation: the LanguageServerWrapper.java diff could not be read because changed blobs are missing, and the file read was truncated before shutdownAll. The verdict relies on the PR summary and description, not on a direct read of the changed hunk or test body.

Full details: Out of Scope Changes check

Explanation

The PR changes two files: LanguageServerWrapper.java (about +22 lines, in shutdownAll) and SocketLanguageServerTest.java (about +124 lines, a new test with a delaying provider and supporting imports). Both changes serve the objective of issue #2012: the production change implements the bounded wait, and the test verifies the exit ordering. No unrelated change is described. Limitation: the changed hunks could not be read directly, so this verdict relies on the PR summary.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a7d49860-e955-4c2d-a54c-93befdab48d4
Commits

Reviewing files that changed from the base of the PR and between 291a09e and 81bce1b.

Files selected for processing: 2

  • src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java
  • src/test/java/com/redhat/devtools/lsp4ij/server/SocketLanguageServerTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the shutdown change that waits for queued messages before stopping the connection provider.

No open issues 🎉

What changed in this PR

Addresses #2012 by waiting for queued messages, including exit, to finish writing before stopping a language server’s connection provider.

Changes:

  • Adds a message-writer wait capped at one second, while preserving the no-wait behavior for disposed servers.
  • Adds a socket regression test that delays writing exit and checks that the server receives it without lifecycle errors.
File Description
src/​test/​java/​com/​redhat/​devtools/​lsp4ij/​server/​SocketLanguageServerTest.java Adds delayed-write coverage for delivery of exit during shutdown.
src/​main/​java/​com/​redhat/​devtools/​lsp4ij/​LanguageServerWrapper.java Waits for queued writes before stopping the connection provider.

Review effort: Balanced

@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.13%. Comparing base (291a09e) to head (81bce1b).

Files with missing lines Patch % Lines
.../redhat/devtools/lsp4ij/LanguageServerWrapper.java 40.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2013      +/-   ##
==========================================
- Coverage   49.17%   49.13%   -0.05%     
==========================================
  Files         812      812              
  Lines       33017    33027      +10     
  Branches     6750     6751       +1     
==========================================
- Hits        16237    16228       -9     
- Misses      14235    14254      +19     
  Partials     2545     2545              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lagergren lagergren added the bug Something isn't working label Nov 17, 2026
@lagergren lagergren added this to the 0.30.0 milestone Nov 17, 2026
@lagergren

Copy link
Copy Markdown
Collaborator

Agreed This is a bug and should go in 0.30.0

@lagergren lagergren left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The socket transport is new in 0.30.0 (#1870), so this fixes it before its first release. CI is green on all platforms, and locally SocketLanguageServerTest passed three runs in a row.

@lagergren
lagergren merged commit 0bdec3f into redhat-developer:main Nov 17, 2026
9 checks passed
@d-biehl
d-biehl deleted the fix/send-exit-before-closing-the-connection branch November 18, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants