Skip to content

fix: stop a language server without waiting for a write action of the UI thread - #2069

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/stop-a-language-server-without-waiting-for-a-write-action
Nov 21, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/stop-a-language-server-without-waiting-for-a-write-action

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

LanguageServerWrapper.stop() holds the monitor of the language server, and disposes the supports of the files of the stopped language server in a non-blocking read action (disposeFileSupports). Its comment says it must not wait for a read action, but its expireWith(project) registers on the project in a read action that submit() runs at once (NonBlockingReadActionImpl.Submission), which waits while a write action runs. So a stop from a thread of the pool, as an idle stop or a restart, waited with the monitor held for a write action of the UI thread, which can need that monitor in the write action: the same kind of deadlock as #2065.

The read action now expires with expireWhen(project::isDisposed), as EditorFeatureManager.refreshEditorFeature does since #1853 for the same reason, which registers nothing at submission.

This is what is left of that kind of deadlock after #2065. Of the 17 non-blocking read actions that register on a disposable at submission (expireWith, withDocumentsCommitted, inSmartMode), the others are submitted on the UI thread or in a read action, where the read action of submit() doesn't wait, or hold no lock while they wait.

Test: StopWithoutWaitingForAWriteActionTest stops a language server with a connected file from a thread of the pool while the UI thread holds a write action, and waits for 10 seconds at most: without the change, the stop waits for the write action, and the test fails. It and the other stop tests pass (24 tests), as does the whole suite (1794 tests, 7 skipped).

… UI thread

stop() holds the monitor of the language server and disposes the supports of its files in a non-blocking read action,
whose expireWith(project) registered on the project in a read action taken at submission: from a thread of the pool,
the stop waited for a write action of the UI thread with the monitor held. The read action now expires with
expireWhen(project::isDisposed), as EditorFeatureManager.refreshEditorFeature does since redhat-developer#1853.
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Language server file-support operations now expire when their project is disposed, helping prevent shutdown from waiting on work associated with a closed project. Stopping a language server from another thread while the UI is performing a write action is also covered by a regression test.

The non-blocking read action now expires when the project is disposed. A new test checks that wrapper.stop() completes while the UI thread holds a write action.

Changes: Wrapper stop behavior

Layer / File(s) Summary
Disposal handling and stop test
src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java, src/test/java/com/redhat/devtools/lsp4ij/StopWithoutWaitingForAWriteActionTest.java
The non-blocking read action uses expireWhen(project::isDisposed) instead of expireWith(project). The test checks that wrapper.stop() completes within 10 seconds while a UI-thread write action is held.

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

Change: Bug fix

Suggested reviewers: angelozerr, d-biehl

Merge Risk: Minimal · up to ce798

This change lets stopping a language server from a background thread complete while the UI thread holds a write action, and adds a regression test for it. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: LanguageServerWrapper.stop() no longer waits for a UI-thread write action. The raw summary confirms the fix replaces expireWith(project) with expireWhen(project::isDi…
Description check Passed The description explains the deadlock path in LanguageServerWrapper.stop() and disposeFileSupports, the expireWhen(project::isDisposed) change, and the new StopWithoutWaitingForAWriteActionTest test. …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title states the main change: LanguageServerWrapper.stop() no longer waits for a UI-thread write action. The raw summary confirms the fix replaces expireWith(project) with expireWhen(project::isDisposed) in disposeFileSupports, and a test covers the stop path. The title is specific and matches the changeset. It is long (79 characters) but still readable.

Full details: Description check

Explanation

The description explains the deadlock path in LanguageServerWrapper.stop() and disposeFileSupports, the expireWhen(project::isDisposed) change, and the new StopWithoutWaitingForAWriteActionTest test. It is directly related to the changeset.

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: 14605779-e09f-415b-a663-f421b02ecd4b
Commits

Reviewing files that changed from the base of the PR and between 36bc568 and ce79877.

Files selected for processing: 2

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

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

@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.17%. Comparing base (bba340e) to head (ce79877).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2069      +/-   ##
==========================================
+ Coverage   49.91%   50.17%   +0.26%     
==========================================
  Files         813      813              
  Lines       33396    33483      +87     
  Branches     6872     6888      +16     
==========================================
+ Hits        16668    16799     +131     
+ Misses      14138    14055      -83     
- Partials     2590     2629      +39     

☔ 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

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren
lagergren merged commit 7ff4a95 into redhat-developer:main Nov 21, 2026
13 of 14 checks passed
lagergren added a commit that referenced this pull request Nov 21, 2026
…isposes its synchronizer (#2071)

Builds on #2065, now merged. Holding the documents lock while the diagnostics are published is safe only once their refresh doesn't wait for a write action, which #2065 makes so.

The `Test (ubuntu-latest, 2025.3)` job of #2069 hung in `WorkspaceDiagnosticsTest.testCloseFiltersWorkspacePullWithoutPreviousResultId` ([run](https://github.com/redhat-developer/lsp4ij/actions/runs/44898419103/job/136828939030)), on a deadlock that #2069 doesn't touch:

- The UI thread closes the file: `LanguageServerWrapper.disconnect` holds the documents lock of the language server (`documentsLock`) and disposes the synchronizer of the document, whose `dispose()` waits for the lock of its diagnostics (`diagnosticLifetime`).
- A thread of the pool applies a pulled report holding `diagnosticLifetime`, held so that a disposal waits for the publication (#1699). The publication of the diagnostics of a document that isn't open, as the one being closed, or a related document of the report, takes `documentsLock` (`LanguageServerWrapper.getClosedDocument`), and waits for the UI thread.

The synchronizer now takes `documentsLock` before `diagnosticLifetime` when it applies a report, in the order of the disconnect (`LanguageServerWrapper.getDocumentsLock`). No other code takes `diagnosticLifetime` and then `documentsLock`. The disposal still waits for a publication under way, as before.

Test: `PulledReportDisconnectTest` holds the documents lock, as a disconnect does, asks for a pull whose report has a related document that isn't open, waits until the thread that applies the report waits for the documents lock, and disposes the synchronizer: without the change, the two wait for each other, as on the runner, and the test hangs; with it, the disposal ends at once. The diagnostics, pull and document tests pass (110 tests), as does the whole suite (1777 tests, 7 skipped).
@lagergren lagergren added the bug Something isn't working label Nov 22, 2026
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.

1 participant