[threading] IJPL-216787: Avoid deadlock with synchronous refresh invoked inside background write action

GitOrigin-RevId: e4a3a51cf17acf430cce38165377a7d7d06126a7
This commit is contained in:
Konstantin Nisht
2025-11-04 19:19:47 +00:00
committed by intellij-monorepo-bot
parent d607ec531d
commit 943655cbdc
2 changed files with 14 additions and 1 deletions
@@ -70,7 +70,7 @@ class RefreshQueueImpl(coroutineScope: CoroutineScope) : RefreshQueue(), Disposa
queueSession(session, session.modality)
}
}
else if (EDT.isCurrentThreadEdt()) {
else if (EDT.isCurrentThreadEdt() || ApplicationManager.getApplication().isWriteAccessAllowed) {
(TransactionGuard.getInstance() as TransactionGuardImpl).assertWriteActionAllowed()
val events = runRefreshSession(session, -1L)
fireEvents(events, session)
@@ -231,4 +231,17 @@ class VfsRefreshTest {
}
assertEquals(currentCounter, newCounter, "There should be no write action if there was nothing to refresh")
}
@Test
fun `synchronous refresh in a background write action can terminate successfully`() = timeoutRunBlocking {
val file = createTempFile()
val virtualFile = VirtualFileManager.getInstance().findFileByNioPath(file)!!
writeAction {
virtualFile.writeText("42")
}
backgroundWriteAction {
virtualFile.refresh(false, false)
}
// if this test terminates, there was no hanging
}
}