[platform] initialize RunManager under read action to fix deadlock (IDEA-303213)

It may happen that RunManagerImpl::loadState invokes Read Action (e.g. inside BuildArtifactsBeforeRunTaskBase.readExternal), so if we don't invoke the whole initialization under Read Action, we may get a deadlock if some other thread accesses RunManager (and triggers its initialization) under Write Action, or accesses it under Read Action while other Write Action is pending.

GitOrigin-RevId: 8009acb892fbb3b1f24bd1b29db51d84d894db28
This commit is contained in:
Nikolay Chashnikov
2022-10-07 18:09:02 +02:00
committed by intellij-monorepo-bot
parent 2c9e706f09
commit 394d8ad5cf

View File

@@ -4,6 +4,7 @@ package com.intellij.execution.impl
import com.intellij.diagnostic.runActivity
import com.intellij.execution.RunManager
import com.intellij.execution.RunManager.Companion.IS_RUN_MANAGER_INITIALIZED
import com.intellij.openapi.application.readAction
import com.intellij.openapi.components.ComponentManagerEx
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.project.Project
@@ -25,7 +26,9 @@ private class ProjectRunConfigurationInitializer : ProjectServiceContainerInitia
runActivity("RunManager initialization") {
// we must not fire beginUpdate here, because message bus will fire queued parent message bus messages (and, so, SOE may occur because all other projectOpened will be processed before us)
// simply, you should not listen changes until project opened
(project as ComponentManagerEx).getServiceAsync(RunManager::class.java).join()
readAction {
RunManager.getInstance(project)
}
IS_RUN_MANAGER_INITIALIZED.set(project, true)
}
}