Repository navigation
Description
A language server's stop disconnects its open documents, and each disconnection holds documentsLock while it disposes the document's synchronizer. With changes of the document not sent yet, the synchronizer sends them first, and on a thread without read access it reads the document in a non-blocking read action, which waits while a write action is pending or running. The rename or move of a file disconnects its document under documentsLock in its write action. The stop then waits for the write action, and the write action for documentsLock, which the stop holds, so the UI thread hangs.
How it happens
LanguageServerWrapper.stopdisconnects every open document:
lsp4ij/src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java
Lines 2535 to 2537 in b2eeaf7
while (!this.openedDocuments.isEmpty()) { disconnect(this.openedDocuments.keySet().iterator().next(), false); } disconnectdisposes the synchronizer underdocumentsLock:
lsp4ij/src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java
Lines 1369 to 1381 in b2eeaf7
void disconnect(@Nullable URI fileUri, boolean stopIfNoOpenedFiles) { if (fileUri == null) { return; } synchronized (documentsLock) { scopedDocuments.remove(fileUri); OpenedDocument openedDocument = this.openedDocuments.remove(fileUri); if (openedDocument != null) { // Remove the listener from the old document stored in synchronizer DocumentContentSynchronizer synchronizer = openedDocument.getSynchronizer(); if (synchronizer != null) { Disposer.dispose(synchronizer); } DocumentContentSynchronizer.documentClosedsends the pending changes first:
lsp4ij/src/main/java/com/redhat/devtools/lsp4ij/DocumentContentSynchronizer.java
Lines 544 to 548 in b2eeaf7
// Without this call, the didChange notification could be sent // after didClose, breaking the expected LSP event order. if (!changeEvents.isEmpty()) { sendDidChangeEvents(); }
and on a thread without read access,readDocumentStatereads the document inrunCancellableReadAction, which isReadAction.nonBlocking(...).executeSynchronously():
lsp4ij/src/main/java/com/redhat/devtools/lsp4ij/DocumentContentSynchronizer.java
Lines 337 to 342 in b2eeaf7
private <T> T readDocumentState(@NotNull Supplier<T> read) { if (ApplicationManager.getApplication().isReadAccessAllowed()) { return read.get(); } return runCancellableReadAction(read::get, languageServerWrapper); } LSPFileListener.onFileRenameAfter, in the write action of the rename, callsdisconnectIfConnected, which takesdocumentsLock:
if (languageServerWrapper.disconnectIfConnected(oldFileUri)) {
Since fix: follow-ups to several instances of one language server per project #1891 it takes the lock for every rename that the listener handles; before,disconnecttook it for a connected document.
It needs a stop on a thread without read access while a document has unsent changes, and a rename or move at that moment, so it's rare. It was found by reading the code in the review of #1891 (thread), and hasn't been reproduced.
Possible direction
Don't wait for a read action while holding documentsLock: take the document out of the maps under the lock, and dispose its synchronizer, which sends the pending changes and didClose, after releasing the lock, keeping the didClose ahead of a later didOpen of the same URI.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
lagergren commentedon Nov 9, 2026
This is a regression of this release cycle: 0.21.0 doesn't have it. There,
disconnectdisposed the synchronizer without holdingdocumentsLock, andsendDidChangeEventssent the pending changes without a read action. Our #1707 (2680f3b1) put the dispose underdocumentsLock, and our #1698 (ff834ce1) made the pending changes wait for a read action, both merged 2026-10-19; #1891 then made every rename that the listener handles take the lock. So 0.30.0 would ship a freeze that 0.21.0 doesn't have.@angelozerr, could you put it on the 0.30.0 milestone? I'm preparing the fix.
angelozerr commentedon Nov 9, 2026
done
fix: send a closing document's pending changes without waiting for a …