Skip to content

fix: schedule a refresh of the diagnostics without waiting for a write action, whatever lock the caller holds - #2065

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/schedule-a-diagnostics-refresh-without-waiting-for-a-write-action
Nov 21, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/schedule-a-diagnostics-refresh-without-waiting-for-a-write-action

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

The Test (ubuntu-latest, 2025.3) job of main hung at 873746d (run): PullResultIdTest.testEachPullSendsTheResultIdOfTheLastReportApplied ran for 5 minutes, and the test JVM ended with a thread dump. It is a deadlock, which can freeze the IDE as well:

  • A thread of the pool applies a pulled diagnostic report, holding the lock of the document's diagnostics (DocumentContentSynchronizer.diagnosticLifetime, held so that a disposal waits for the publication). OpenedDocument.updateDiagnostics calls LSPDiagnosticsApplier.scheduleRefresh, whose submit() runs a read action, to register the project that withDocumentsCommitted(project) adds (NonBlockingReadActionImpl.Submission). The read action waits for the write action of the UI thread.
  • The UI thread, in that write action, inserts a character into the document: documentChanged asks for a pull (refreshPullDiagnostic), which takes the same lock to read the result ID of the last report.

scheduleRefresh now 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 before scheduleRefresh returns. From the UI thread or in a read action, the read action of submit() doesn't wait, and the refresh is submitted at once, as before.

Test: LSPDiagnosticsApplierTest.testARefreshScheduledFromAnotherThreadDoesNotWaitForTheWriteActionOfTheUIThread schedules 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).

…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.
@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
    • Improved diagnostics refresh reliability when updates occur during write actions, helping results appear once the action completes.
    • Prevented diagnostics refreshes from remaining pending when a project is disposed or refresh scheduling fails.

Diagnostics refresh submission now runs immediately when the application thread or read-access conditions allow. Otherwise, it queues the refresh on the application executor. A test checks refresh scheduling while a write action is held.

Changes: Diagnostics refresh scheduling

Layer / File(s) Summary
Refresh submission and validation
src/main/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplier.java, src/test/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplierTest.java
Refresh work runs immediately on the dispatch thread or when read access is allowed; otherwise, it is queued on the application executor. Submission failures and disposed projects end the refresh. The test checks scheduling and refresh state while a write action is held.

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

Change: Bug fix

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to bd40f

This change avoids a deadlock when diagnostics refreshes are scheduled from background threads while the UI thread holds a write action. No actionable merge-blocking risk was found, and the change is covered by a targeted test.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title says the refresh of diagnostics is scheduled without waiting for a write action, whatever lock the caller holds. The raw summary and objectives confirm that scheduleRefresh now submits refre…
Description check Passed The description explains the deadlock being fixed, the mechanism of the change in scheduleRefresh, and the added test LSPDiagnosticsApplierTest. It is directly related to the changeset.
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 says the refresh of diagnostics is scheduled without waiting for a write action, whatever lock the caller holds. The raw summary and objectives confirm that scheduleRefresh now submits refreshes from another pool thread when called outside the UI thread and read actions, so the scheduling does not wait for a write action. The title matches the main change, though it is long and uses the 'fix:' prefix with a somewhat wordy phrasing.

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: 0fe9b013-804f-4ceb-971e-373bb684d376
Commits

Reviewing files that changed from the base of the PR and between bba340e and bd40fed.

Files selected for processing: 2

  • src/main/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplier.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplierTest.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

❌ Patch coverage is 28.57143% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.89%. Comparing base (30adef2) to head (bd40fed).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...ij/features/diagnostics/LSPDiagnosticsApplier.java 28.57% 8 Missing and 2 partials ⚠️
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.
📢 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 7793318 into redhat-developer:main Nov 21, 2026
13 of 14 checks passed
@lagergren lagergren added this to the 0.30.2 milestone Nov 21, 2026
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).
@lagergren lagergren added bug Something isn't working diagnostic labels 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 diagnostic

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant