Fix deadlock in Extract Method when multiple scopes exist#713
Fix deadlock in Extract Method when multiple scopes exist#713nafg wants to merge 1 commit intoJetBrains:idea253.xfrom
Conversation
…st #SCL-25001 fixed Replace PsiTargetNavigator with JBPopupFactory in showPsiChooser to avoid a deadlock caused by runBlocking on the EDT. PsiTargetNavigator.createPopup() internally calls computeItems() which uses runBlocking, blocking the EDT while dispatching work to coroutine workers. Those workers contend for the indexing lock (ChangeTrackingValueContainer), which can't be released because the EDT is blocked. This causes a permanent deadlock (34 threads blocked). The fix delegates to showChooserGeneric which uses JBPopupFactory — a safe popup mechanism already used elsewhere in the same file. Also related: JetBrains#712 Co-Authored-By: Claude Code (Anthropic) <noreply@anthropic.com>
ebccf84 to
985eb4a
Compare
|
[Comment authored by Claude Code on behalf of @nafg] @unkarjedy Thanks for the quick response! Clarification: The deadlock is a race condition, not a guaranteed freeze. It requires two conditions simultaneously:
Without index contention, the Re: manual verification — I haven't tested the built plugin yet. I'm planning to upgrade to the latest EAP, reproduce the deadlock, then verify the fix. The change itself is minimal: I'll follow up once I've verified. |
|
[Comment authored by Claude Code on behalf of @nafg] Reproduction attempt on 2026.1 EAP: I upgraded to IntelliJ IDEA 2026.1 EAP and attempted to reproduce the deadlock. I was unable to trigger it — even while running Find Usages on This is consistent with it being a race condition: the original deadlock (captured in the thread dump from 2025.3) required the That said, the underlying issue — |
|
Make what you like of Claude's opinions... Find Occurrences seems WAY faster and smoother btw |
|
@nafg Thanks for checking it!
I primarily meant to check that there is no regressions in the feature behavior and it works. I am asking just in case, because in the past we had some AI-generated trash PR that had ton's of mistakes and it turned out it was reported by an agent and the user never even tried to verify it. Thanks, we will look into it |
YouTrack: SCL-25001
Summary
PsiTargetNavigatorwithJBPopupFactoryinshowPsiChooserto fix a deadlock that can freeze IntelliJ when "Extract Method" is invoked on code with multiple extraction scopes while another operation holds the indexing lockProblem
PsiTargetNavigator.createPopup()internally callsrunBlockingon the EDT viacomputeItems()→Utils.computeWithProgressIcon(). The dispatched coroutine workers then contend for the indexing lock (ChangeTrackingValueContainer), which can't be released because the EDT is blocked. This creates a permanent deadlock with 34 threads blocked.This is a race condition — it requires both multiple extraction scopes (triggering
PsiTargetNavigator) AND concurrent index lock contention (e.g., Find Occurrences running at the same time). It does not freeze every time, butrunBlockingon the EDT is still architecturally wrong.See SCL-25001 for full thread dump analysis.
Fix
showPsiChoosernow delegates toshowChooserGeneric, which usesJBPopupFactory— a safe popup mechanism that doesn't userunBlocking. This method already exists in the same file and provides the same functionality (title, presentation, highlighting, selection callback).The items passed to
showPsiChooserare already fully computedPsiElements with pre-computed presentation strings, so there is no need for the async computation thatPsiTargetNavigatorprovides.Test plan
ScalaExtractMethodTestBase,ScalaExtractMethodScopeTest, etc.)