Repository navigation
fix: schedule a refresh of the diagnostics without waiting for a write action, whatever lock the caller holds - #2065
Merged
Conversation
…e action, whatever lock the caller holds LSPDiagnosticsApplier.scheduleRefresh submits a non-blocking read action, whose submit() runs a read action to register the project of withDocumentsCommitted, and so waits while a write action runs. A document that applies a pulled report holds the lock of its diagnostics, which the UI thread takes as the document changes in a write action: the two waited for each other, as PullResultIdTest did on the 2025.3 job of main. From a thread which is neither the UI thread nor in a read action, the refresh is now submitted from another thread of the pool. It is still pending before scheduleRefresh returns.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2065 +/- ##
==========================================
+ Coverage 49.49% 49.89% +0.40%
==========================================
Files 813 813
Lines 33345 33410 +65
Branches 6854 6874 +20
==========================================
+ Hits 16503 16670 +167
+ Misses 14266 14144 -122
- Partials 2576 2596 +20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
@coderabbitai review |
Action not completed
|
Collaborator
Author
|
@coderabbitai review |
Action performed
|
lagergren
added a commit
that referenced
this pull request
Nov 21, 2026
… UI thread (#2069) `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).
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
Test (ubuntu-latest, 2025.3)job of main hung at 873746d (run):PullResultIdTest.testEachPullSendsTheResultIdOfTheLastReportAppliedran for 5 minutes, and the test JVM ended with a thread dump. It is a deadlock, which can freeze the IDE as well:DocumentContentSynchronizer.diagnosticLifetime, held so that a disposal waits for the publication).OpenedDocument.updateDiagnosticscallsLSPDiagnosticsApplier.scheduleRefresh, whosesubmit()runs a read action, to register the project thatwithDocumentsCommitted(project)adds (NonBlockingReadActionImpl.Submission). The read action waits for the write action of the UI thread.documentChangedasks for a pull (refreshPullDiagnostic), which takes the same lock to read the result ID of the last report.scheduleRefreshnow submits the refresh from another thread of the pool when it is called from a thread which is neither the UI thread nor in a read action, so that it never waits for a write action, whatever lock its caller holds. The refresh is still tracked as pending beforescheduleRefreshreturns. From the UI thread or in a read action, the read action ofsubmit()doesn't wait, and the refresh is submitted at once, as before.Test:
LSPDiagnosticsApplierTest.testARefreshScheduledFromAnotherThreadDoesNotWaitForTheWriteActionOfTheUIThreadschedules a refresh 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 scheduling waits for the write action, and the test fails. The diagnostics, pull and disposal tests pass (94 tests), as does the whole suite (1776 tests, 7 skipped).