Skip to content

fix: deadlock between completionItem/resolve and publishDiagnostics freezes the IDE while typing - #1689

Merged
angelozerr merged 2 commits into
redhat-developer:mainfrom
halflifefan:fix/completion-resolve-deadlock
Oct 9, 2026
Merged

angelozerr merged 2 commits into
redhat-developer:mainfrom
halflifefan:fix/completion-resolve-deadlock

Conversation

@halflifefan

@halflifefan halflifefan commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Since 0.20.2 / 0.21.0, the IDE can deadlock while you type with a completion popup open, and it has to be killed. I hit it with LuaLS (through Intellij-SumnekoLua) on IntelliJ IDEA 2026.2.3 and lsp4ij 0.21.0. It can happen with any server that supports completionItem/resolve and publishes diagnostics while you type.

Two threads are involved:

  • The EDT is inside the typing write action. LookupCellRenderer.updateItemPresentation calls LSPCompletionProposal.getExpensiveRenderer(), which waits for completionItem/resolve of the selected item with awaitWithCheckCanceled. Nothing can cancel that wait inside a write action.
  • LS-…#messageWriter is handling textDocument/publishDiagnostics. LSPDiagnosticsForServer.toMap creates LSPLazyCodeActions, whose constructor calls LSPIJUtils.getPsiFile, and that waits for the write action to finish.

Since #1621, every inbound message, responses included, is handled on that one messageWriter thread, so the resolve response is stuck behind the blocked notification. Before #1649 the EDT wait was capped at 500 ms inside a write action. Without the cap, the deadlock is permanent.

Thread dump (0.21.0)
"AWT-EventQueue-0" TIMED_WAITING
  at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2116)
  at com.intellij.openapi.progress.util.ProgressIndicatorUtils.awaitWithCheckCanceled(ProgressIndicatorUtils.java:374)
  at com.redhat.devtools.lsp4ij.client.features.LSPCompletionProposal.getResolvedCompletionItem(LSPCompletionProposal.java:500)
  at com.redhat.devtools.lsp4ij.client.features.LSPCompletionProposal.getExpensiveRenderer(LSPCompletionProposal.java:281)
  at com.intellij.codeInsight.lookup.LookupElementDecorator.getExpensiveRenderer(LookupElementDecorator.java:108)
  at com.intellij.codeInsight.lookup.impl.LookupCellRenderer.updateItemPresentation(LookupCellRenderer.kt:640)
  at com.intellij.codeInsight.lookup.impl.LookupCellRenderer.scheduleVisibleItemsExpensiveRendering(LookupCellRenderer.kt:607)
  at com.intellij.codeInsight.lookup.impl.LookupImpl.updateList(LookupImpl.java:636)
  at com.intellij.codeInsight.lookup.impl.LookupImpl.appendPrefix(LookupImpl.java:513)
  at com.intellij.codeInsight.lookup.impl.LookupTypedHandler.addCharToPrefix(LookupTypedHandler.java:160)
  ...
  at com.intellij.platform.locking.impl.NestedLocksThreadingSupport.runWriteActionBlocking(NestedLocksThreadingSupport.kt:1006)
  at com.intellij.openapi.editor.impl.DefaultRawTypedHandler.execute(DefaultRawTypedHandler.java:59)

"LS-SumnekoLua@<project>#messageWriter" TIMED_WAITING
  at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.blockUntilWriteActionIsDone(NonBlockingReadActionImpl.java:715)
  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)

Fix

Two commits. Either fixes the deadlock. Commit 2 also stops typing from stalling on slow servers.

  1. LSPLazyCodeActions keeps the VirtualFile it is given instead of looking up the PsiFile, which it only used to get the VirtualFile back. publishDiagnostics no longer waits for the write action.
  2. getExpensiveRenderer() returns the renderer right away, and the renderer does the resolve. IntelliJ calls getExpensiveRenderer() on the EDT, but runs the renderer in a background read action that the next write action cancels, so waiting there is fine. The resolve request can now be created from both the EDT and background threads, so it is created once, under a lock.

Tests

  • LSPLazyCodeActionsTest: creating LSPLazyCodeActions on a pooled thread while the EDT holds a write action must not block, and textDocument/codeAction still gets the right URI and range.
  • CompletionExpensiveRendererTest: inside a write action, getExpensiveRenderer() must return without waiting for a resolve that never completes. A watchdog completes it after 10 s, so the test fails instead of hanging. Running the renderer off the EDT then applies the resolved detail.
  • Both tests fail on main and pass with this PR. MockTextDocumentService gets lastCodeActionParams and setResolveCompletionItemProcessor for them.
  • Full suite on Windows: 458 tests, 0 failures, 3 skipped. RustDiagnosticsTest fails when run alone, on main too, but passes in the full run.

halflifefan and others added 2 commits October 8, 2026 22:09
…c code actions

textDocument/publishDiagnostics is handled on the language server's single
message thread, and LSPLazyCodeActions resolved the PsiFile of the diagnosed
file in its constructor through a cancellable read action. While the EDT
holds a write action, that read action waits for it to finish. Since the
message thread also delivers responses, an EDT waiting inside a write action
for one of them (completionItem/resolve while typing, from
LSPCompletionProposal#getExpensiveRenderer) can never get it, and the IDE
freezes until it is killed.

The PsiFile was only used to get back its VirtualFile for the
textDocument/codeAction request, so keep the VirtualFile instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: halflifefan <[email protected]>
… EDT

LSPCompletionProposal#getExpensiveRenderer waited for completionItem/resolve
of the selected item. IntelliJ calls getExpensiveRenderer() itself on the
EDT, inside the write action of a typed character (LookupTypedHandler ->
LookupImpl#updateList -> LookupCellRenderer#updateItemPresentation), and
runs only the returned renderer in the background. Since
awaitWithCheckCanceled has no cancelable indicator there, a slow server
stalled typing, and a response stuck behind a message waiting for that
write action froze the IDE for good.

Return the renderer right away and resolve the detail in it, where the
read action is canceled by the next write action. The resolve request is
now created from both the EDT and background threads, so create it once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: halflifefan <[email protected]>
@angelozerr

Copy link
Copy Markdown
Contributor

I had never this issue but your explanation sounds very good.

Let me test your PR

@angelozerr
angelozerr merged commit 69c3ada into redhat-developer:main Oct 9, 2026
4 of 8 checks passed
@angelozerr

Copy link
Copy Markdown
Contributor

Nice catch! Thanks @halflifefan !

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants