Repository navigation
fix: deadlock between completionItem/resolve and publishDiagnostics freezes the IDE while typing - #1689
Merged
angelozerr merged 2 commits intoOct 9, 2026
Conversation
…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]>
Contributor
|
I had never this issue but your explanation sounds very good. Let me test your PR |
Contributor
|
Nice catch! Thanks @halflifefan ! |
andreysubbotin
added a commit
to Amplicode/lsp4ij
that referenced
this pull request
Nov 6, 2026
fix: completion freeze — resolve ↔ publishDiagnostics deadlock (port of redhat-developer#1689)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/resolveand publishes diagnostics while you type.Two threads are involved:
LookupCellRenderer.updateItemPresentationcallsLSPCompletionProposal.getExpensiveRenderer(), which waits forcompletionItem/resolveof the selected item withawaitWithCheckCanceled. Nothing can cancel that wait inside a write action.LS-…#messageWriteris handlingtextDocument/publishDiagnostics.LSPDiagnosticsForServer.toMapcreatesLSPLazyCodeActions, whose constructor callsLSPIJUtils.getPsiFile, and that waits for the write action to finish.Since #1621, every inbound message, responses included, is handled on that one
messageWriterthread, 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)
Fix
Two commits. Either fixes the deadlock. Commit 2 also stops typing from stalling on slow servers.
LSPLazyCodeActionskeeps theVirtualFileit is given instead of looking up thePsiFile, which it only used to get theVirtualFileback.publishDiagnosticsno longer waits for the write action.getExpensiveRenderer()returns the renderer right away, and the renderer does the resolve. IntelliJ callsgetExpensiveRenderer()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: creatingLSPLazyCodeActionson a pooled thread while the EDT holds a write action must not block, andtextDocument/codeActionstill 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.mainand pass with this PR.MockTextDocumentServicegetslastCodeActionParamsandsetResolveCompletionItemProcessorfor them.RustDiagnosticsTestfails when run alone, onmaintoo, but passes in the full run.