Skip to content

fix: apply a pulled report in the lock order of a disconnect, which disposes its synchronizer - #2071

Merged
lagergren merged 3 commits into
redhat-developer:mainfrom
lagergren:fix/apply-a-pulled-report-in-the-lock-order-of-a-disconnect
Nov 21, 2026
Merged

lagergren merged 3 commits into
redhat-developer:mainfrom
lagergren:fix/apply-a-pulled-report-in-the-lock-order-of-a-disconnect

Conversation

@lagergren

@lagergren lagergren commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

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), 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 (fix: stop pull diagnostics after document disposal #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).

…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.
…isposes its synchronizer

A document synchronizer applied a pulled report holding the lock of its diagnostics, and the publication of the
diagnostics of a document that isn't open takes the documents lock of the language server. A disconnect holds the
documents lock while it disposes the synchronizer, which takes the lock of its diagnostics: the two waited for each
other, as WorkspaceDiagnosticsTest did on the 2025.3 job of redhat-developer#2069. The synchronizer now takes the documents lock
first, as the disconnect does.
@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 synchronization between diagnostic updates and language server disconnects, preventing potential hangs when reports arrive during document cleanup.
    • Diagnostic updates continue to respect document state and version checks, preventing stale or retired reports from overwriting current diagnostics.

Pull-diagnostic reply handling now acquires the language server’s documents lock before the diagnostic lifetime lock. A new test exercises report application while a disconnect-like thread holds the documents lock and disposes the synchronizer.

Changes: Pulled diagnostic synchronization

Layer / File(s) Summary
Lock and validate pulled diagnostic reports
src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java, src/main/java/com/redhat/devtools/lsp4ij/DocumentContentSynchronizer.java, src/test/java/com/redhat/devtools/lsp4ij/PulledReportDisconnectTest.java
LanguageServerWrapper exposes the documents lock. Pull-diagnostic reply handling acquires it before the diagnostic lifetime lock, with existing rejection checks and report updates under both locks. The new test exercises report application during synchronizer disposal while the documents lock is held.

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

Change: Bug fix

Suggested reviewers: angelozerr, d-biehl

Merge Risk: Minimal · up to 84c27

This change fixes a deadlock between disconnecting a language server and applying a pulled diagnostics report by making both take the same locks in the same order. No concrete defect was found, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a pulled diagnostic report is now applied in the documents-lock order used by disconnect, which disposes the synchronizer. This matches the DocumentContentSynchronizer…
Description check Passed The description explains the deadlock between disconnect (documentsLock, then diagnosticLifetime via synchronizer dispose) and pulled report application (diagnosticLifetime, then documentsLock during …
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 names the main change: a pulled diagnostic report is now applied in the documents-lock order used by disconnect, which disposes the synchronizer. This matches the DocumentContentSynchronizer change, the new getDocumentsLock accessor, and the new deadlock test. The title is specific and concise, though somewhat long at 93 characters.

Full details: Description check

Explanation

The description explains the deadlock between disconnect (documentsLock, then diagnosticLifetime via synchronizer dispose) and pulled report application (diagnosticLifetime, then documentsLock during publication). It names the changed code (getDocumentsLock, DocumentContentSynchronizer), describes the new PulledReportDisconnectTest, and reports test results. 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: 9698f66f-d74c-44be-a2b8-9d6147f20e97
Commits

Reviewing files that changed from the base of the PR and between a800041 and 84c273b.

Files selected for processing: 2

  • src/main/java/com/redhat/devtools/lsp4ij/DocumentContentSynchronizer.java
  • src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.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 85.71429% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.16%. Comparing base (7793318) to head (84c273b).

Files with missing lines Patch % Lines
...t/devtools/lsp4ij/DocumentContentSynchronizer.java 84.61% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2071      +/-   ##
==========================================
+ Coverage   50.13%   50.16%   +0.02%     
==========================================
  Files         813      813              
  Lines       33497    33500       +3     
  Branches     5221     6890    +1669     
==========================================
+ Hits        16795    16806      +11     
+ Misses      14070    14063       -7     
+ Partials     2632     2631       -1     

☔ 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 lagergren added this to the 0.30.2 milestone Nov 21, 2026
@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 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 fe9f583 into redhat-developer:main Nov 21, 2026
10 of 11 checks passed
@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