Skip to content

Deadlock: EDT waits for workspace/willDeleteFiles under a write action while the messageWriter thread waits for a read action in publishDiagnostics #1694

Closed

Description

@d-biehl

Environment

  • LSP4IJ 0.21.0
  • PyCharm 2026.1 (build PY-261.22158.340), Linux
  • Language server: RobotCode, which registers workspace.fileOperations.willDelete (and willCreate/willRename) with a glob filter for its file types

What happens

The IDE froze for more than 10 minutes until the process was killed. The freeze report shows a lock cycle between the EDT and LSP4IJ's messageWriter thread:

  1. A VFS refresh (here the initial refresh after opening the project) fires its events in a write action, which is transferred to the EDT. In beforeVfsChange, AbstractLSPFileListener.before sends workspace/willDeleteFiles for a matching file and waits for the result in applyWorkspaceEdit with ProgressIndicatorUtils.awaitWithCheckCanceled on the EDT, without a progress indicator or timeout, while the write action is held.
  2. LanguageServerWrapper passes every message, incoming and outgoing, to CompletableFuture.runAsync(..., messageWriter), and messageWriter is a single-thread executor (LanguageServerWrapper.java:478).
  3. At the same moment the messageWriter thread is handling an incoming textDocument/publishDiagnostics. LSPDiagnosticsForServer.toMap creates LSPLazyCodeActions, whose constructor calls LSPIJUtils.getPsiFile, which runs a non-blocking read action synchronously. That read action waits until the write action of step 1 ends.
  4. The outgoing willDeleteFiles request is queued behind this notification on the same executor, so it is never sent. The server never answers, and the EDT never gets its result. Later messages stay queued as well: the progress of the server's startup analysis never ended in the status bar, while the server process was idle.

Thread dump excerpts

EDT:

at com.intellij.openapi.progress.util.ProgressIndicatorUtils.awaitWithCheckCanceled(ProgressIndicatorUtils.java:387)
at com.redhat.devtools.lsp4ij.features.files.AbstractLSPFileListener.applyWorkspaceEdit(AbstractLSPFileListener.java:248)
at com.redhat.devtools.lsp4ij.features.files.AbstractLSPFileListener.before(AbstractLSPFileListener.java:229)
at com.redhat.devtools.lsp4ij.features.files.AbstractLSPFileListener$1.beforeVfsChange(AbstractLSPFileListener.java:87)
at com.intellij.openapi.vfs.newvfs.AsyncEventSupport.invokeAppliers(AsyncEventSupport.java:171)
...
at com.intellij.openapi.application.impl.TransferredWriteActionServiceImpl.runOnEdtWithTransferredWriteActionAndWait$lambda$0(TransferredWriteActionServiceImpl.kt:11)

Refresh thread (holds the write action and waits for the EDT):

at com.intellij.openapi.application.impl.InternalThreading$TransferredWriteActionEvent.blockingWait(appImpl.kt:252)
at com.intellij.openapi.vfs.newvfs.AsyncEventSupport.processEventsFromRefresh(AsyncEventSupport.java:190)
at com.intellij.openapi.vfs.newvfs.RefreshSessionImpl.fireEventsInWriteAction(RefreshSessionImpl.kt:277)

LS-<server>#messageWriter:

at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.blockUntilWriteActionIsDone(NonBlockingReadActionImpl.java:710)
at com.intellij.openapi.application.impl.NonBlockingReadActionImpl.executeSynchronously(NonBlockingReadActionImpl.java:295)
at com.redhat.devtools.lsp4ij.internal.ApplicationUtils.runCancellableReadAction(ApplicationUtils.java:59)
at com.redhat.devtools.lsp4ij.LSPIJUtils.getPsiFile(LSPIJUtils.java:570)
at com.redhat.devtools.lsp4ij.features.codeAction.quickfix.LSPLazyCodeActions.<init>(LSPLazyCodeActions.java:77)
at com.redhat.devtools.lsp4ij.features.diagnostics.LSPDiagnosticsForServer.toMap(LSPDiagnosticsForServer.java:170)
...
at com.redhat.devtools.lsp4ij.client.LanguageClientImpl.publishDiagnostics(LanguageClientImpl.java:122)
...
at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:192)
at com.redhat.devtools.lsp4ij.LanguageServerWrapper.lambda$start$7(LanguageServerWrapper.java:478)

When it can happen

Whenever a server registers willDelete, willCreate or willRename, a matching file is deleted, created or renamed (the listener runs in the write action of the VFS change, whether it comes from a refresh or from the user), and a publishDiagnostics from the same server is being handled at that moment. Servers that publish diagnostics for many files after startup make this likely right after a project is opened.

Possible directions

  • Do not wait for the server on the EDT while a write action is held, or bound the wait with a timeout so that the file operation goes ahead without the edit.
  • Do not run blocking read actions on the thread that also sends outgoing messages, or use separate executors for incoming and outgoing messages, so that a request can always be sent.

Activity

  1. angelozerr commented on Oct 11, 2026

    @angelozerr
    Contributor

    I think #1689 could fix your issue.

    Could you please install https://github.com/redhat-developer/lsp4ij#testing-nightly-builds and telll me if it fixes your issue

  2. d-biehl commented on Oct 11, 2026

    @d-biehl
    ContributorAuthor

    Thanks! I tested the nightly 0.21.1-20261011-014957, and it fixes the freeze for us.

    Setup in PyCharm 2026.1 (PY-261.22158.340) with the RobotCode language server: a project with 150 suites that each get a diagnostic, workspace diagnostics on, and 20 of the suites open in editors. A script deleted 40 matching files through the VFS, one every 50 ms, and before every second deletion saved a resource file that all suites import, so the server kept publishing diagnostics for the open documents.

    • 0.21.0: the IDE froze after 10 deletions (after 38 in an earlier run), with the same two threads as in the report: the EDT in AbstractLSPFileListener.applyWorkspaceEdit, and messageWriter in LSPLazyCodeActions.<init> → LSPIJUtils.getPsiFile.
    • 0.21.1-20261011-014957: 3 × 40 deletions with the same steps and no freeze. The server received every willDeleteFiles, and the EDT waited 7 ms in the median and 52 ms at most per deletion. No errors in idea.log.

    What remains is that the EDT still waits for the willDeleteFiles answer inside the write action without a timeout. A slow server still blocks the UI for that time, and another blocking read action on the message thread could bring the cycle back. Feel free to close this issue if you'd rather track that separately.

    Do you already have a rough idea when the next LSP4IJ release with this fix will be out?

  3. angelozerr commented on Oct 12, 2026

    @angelozerr
    Contributor

    Thanks! I tested the nightly 0.21.1-20261011-014957, and it fixes the freeze for us.

    That's super great!

    Setup in PyCharm 2026.1 (PY-261.22158.340) with the RobotCode language server: a project with 150 suites that each get a diagnostic, workspace diagnostics on, and 20 of the suites open in editors. A script deleted 40 matching files through the VFS, one every 50 ms, and before every second deletion saved a resource file that all suites import, so the server kept publishing diagnostics for the open documents.

    • 0.21.0: the IDE froze after 10 deletions (after 38 in an earlier run), with the same two threads as in the report: the EDT in AbstractLSPFileListener.applyWorkspaceEdit, and messageWriter in LSPLazyCodeActions.<init> → LSPIJUtils.getPsiFile.
    • 0.21.1-20261011-014957: 3 × 40 deletions with the same steps and no freeze. The server received every willDeleteFiles, and the EDT waited 7 ms in the median and 52 ms at most per deletion. No errors in idea.log.

    Great!

    What remains is that the EDT still waits for the willDeleteFiles answer inside the write action without a timeout. A slow server still blocks the UI for that time, and another blocking read action on the message thread could bring the cycle back. Feel free to close this issue if you'd rather track that separately.

    You mean that we should improve this usecase?

    Do you already have a rough idea when the next LSP4IJ release with this fix will be out?

    There are some few issues that we need to finish and I hope I will create the release soon.

  4. self-assigned this
    on Oct 12, 2026
  5. added
    bug
    on Oct 12, 2026
  6. added this to the 0.21.1 milestone on Oct 12, 2026
  7. angelozerr commented on Oct 12, 2026

    @angelozerr
    Contributor

    Fixed with #1689

  8. angelozerr commented on Oct 12, 2026

    @angelozerr
    Contributor
  9. added 2 commits that reference this issue on Oct 12, 2026
    46cbd36
    8ba210f
  10. d-biehl commented on Oct 12, 2026

    @d-biehl
    ContributorAuthor

    You mean that we should improve this usecase?

    Yes, I meant the wait for the answer without a limit.

    I tested #1695 (build zip 0.21.1-SNAPSHOT from d4514d1). The freeze reproduction from before ran 3 × 40 deletions without a freeze: per deletion the EDT waited 12 ms in the median and 82 ms at most, the server answered all 120 willDeleteFiles requests, and idea.log had no errors.

    To see what #1695 changes, I let the server answer willDeleteFiles only after a delay:

    Server answers after Deleted 0.21.0 #1695
    3 s 3 files outside the IDE, picked up by a VFS refresh EDT blocked for 3067 ms EDT free (longest wait 2 ms), files gone from the VFS after 3064 ms
    30 s a file outside the IDE, with 5 edits in an open editor during the wait not tested EDT free, each edit took at most 14 ms, but the server got 11 willDeleteFiles requests for the file, and it was gone from the VFS only after 35 s
    3 s a file inside the IDE (VirtualFile.delete() in a write action on the EDT, as the Project view's Delete does) EDT blocked for about 3 s per file EDT blocked for about 3 s per file
    120 s a file inside the IDE not tested UI frozen for 2 minutes (idea.log: "UI was frozen for 120056ms"), no progress indicator, no way to cancel

    Deletions outside the IDE. Could it be that LSP4IJ shouldn't send willDeleteFiles here at all? It sends it when git, a terminal or another tool deletes files and the VFS refresh picks that up; at startup it even sent it for 40 files that had been deleted while the IDE was closed. As I read the specification, the request is meant only "as long as the deletion is triggered from within the client either by a user action or by applying a workspace edit", and in these cases the files are already gone from the disk. VS Code doesn't fire it there either: its API documentation for workspace.onWillDeleteFiles says the event is triggered by user gestures or workspace.applyEdit, "but this event is not fired when files change on disk, e.g triggered by another application".

    With #1695 the request is still sent in this case. It no longer blocks the UI, but it is sent again whenever the user edits a file while LSP4IJ waits for the answer (each edit restarts prepareChange). In my test, five edits during the wait led to 11 requests for the same file, and the file disappeared from the IDE only 30 s after the last edit.

    Deletions inside the IDE, the case willDeleteFiles is meant for, don't change with #1695: the write action on the EDT still waits until prepareChange has returned, so the UI blocks for however long the server takes to answer. The specification allows clients to drop results "if computing the edit took too long or if a server constantly fails on this request. This is done to keep deletes fast and reliable." VS Code limits the wait with the setting files.participants.timeout, "Timeout in milliseconds after which file participants for create, rename, and delete are cancelled. Use 0 to disable participants." (default 60000), and while it waits it shows a cancellable notification "Running 'File Delete' participants..." after at most 3 seconds.

    willCreateFiles and willRenameFiles are sent from the same place in LSP4IJ, so they might behave the same; I haven't tested them.

  11. angelozerr commented on Oct 12, 2026

    @angelozerr
    Contributor

    @d-biehl please retry #1695

  12. d-biehl commented on Oct 15, 2026

    @d-biehl
    ContributorAuthor

    I retested the current state of #1695 with the reproduction from this issue; the results are in #1695 (comment). The freeze is gone, and it works for us like this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions