diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.kt b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.kt index dd00805b40fc..0b3024676da8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.kt @@ -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) diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/newvfs/persistent/VfsRefreshTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/newvfs/persistent/VfsRefreshTest.kt index 1da2e8a6278d..f6a044f0d31d 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/newvfs/persistent/VfsRefreshTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/newvfs/persistent/VfsRefreshTest.kt @@ -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 + } } \ No newline at end of file