Index: /trunk/src/VBox/VMM/PDMAsyncCompletionFile.cpp
===================================================================
--- /trunk/src/VBox/VMM/PDMAsyncCompletionFile.cpp	(revision 29586)
+++ /trunk/src/VBox/VMM/PDMAsyncCompletionFile.cpp	(revision 29587)
@@ -912,9 +912,18 @@
 static int pdmacFileEpClose(PPDMASYNCCOMPLETIONENDPOINT pEndpoint)
 {
+    int rc = VINF_SUCCESS;
     PPDMASYNCCOMPLETIONENDPOINTFILE pEpFile = (PPDMASYNCCOMPLETIONENDPOINTFILE)pEndpoint;
     PPDMASYNCCOMPLETIONEPCLASSFILE pEpClassFile = (PPDMASYNCCOMPLETIONEPCLASSFILE)pEndpoint->pEpClass;
 
+    /* Free the cached data. */
+    if (pEpFile->fCaching)
+    {
+        rc = pdmacFileEpCacheFlush(pEpFile);
+        AssertRC(rc);
+        pdmacFileEpCacheDestroy(pEpFile);
+    }
+
     /* Make sure that all tasks finished for this endpoint. */
-    int rc = pdmacFileAioMgrCloseEndpoint(pEpFile->pAioMgr, pEpFile);
+    rc = pdmacFileAioMgrCloseEndpoint(pEpFile->pAioMgr, pEpFile);
     AssertRC(rc);
 
@@ -940,8 +949,4 @@
     }
 
-    /* Free the cached data. */
-    if (pEpFile->fCaching)
-        pdmacFileEpCacheDestroy(pEpFile);
-
     /* Remove from the bandwidth manager */
     pdmacFileBwUnref(pEpFile->pBwMgr);
@@ -1032,5 +1037,5 @@
     if (pEpFile->fCaching)
     {
-        int rc = pdmacFileEpCacheFlush(pEpFile, pTaskFile);
+        int rc = pdmacFileEpCacheFlush(pEpFile);
         AssertRC(rc);
     }
Index: /trunk/src/VBox/VMM/PDMAsyncCompletionFileCache.cpp
===================================================================
--- /trunk/src/VBox/VMM/PDMAsyncCompletionFileCache.cpp	(revision 29586)
+++ /trunk/src/VBox/VMM/PDMAsyncCompletionFileCache.cpp	(revision 29587)
@@ -1144,7 +1144,15 @@
     while (ASMAtomicReadU32(&pEntry->fFlags) & (PDMACFILECACHE_ENTRY_IO_IN_PROGRESS | PDMACFILECACHE_ENTRY_IS_DIRTY))
     {
+        /* Leave the locks to let the I/O thread make progress but reference the entry to prevent eviction. */
+        pdmacFileEpCacheEntryRef(pEntry);
         RTSemRWReleaseWrite(pEndpointCache->SemRWEntries);
+        pdmacFileCacheLockLeave(pCache);
+
         RTThreadSleep(250);
+
+        /* Re-enter all locks */
+        pdmacFileCacheLockEnter(pCache);
         RTSemRWRequestWrite(pEndpointCache->SemRWEntries, RT_INDEFINITE_WAIT);
+        pdmacFileEpCacheEntryRelease(pEntry);
     }
 
@@ -2175,10 +2183,9 @@
 }
 
-int pdmacFileEpCacheFlush(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask)
+int pdmacFileEpCacheFlush(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint)
 {
     int rc = VINF_SUCCESS;
 
-    LogFlowFunc((": pEndpoint=%#p{%s} pTask=%#p\n",
-                 pEndpoint, pEndpoint->Core.pszUri, pTask));
+    LogFlowFunc((": pEndpoint=%#p{%s}\n", pEndpoint, pEndpoint->Core.pszUri));
 
     /* Commit dirty entries in the cache. */
Index: /trunk/src/VBox/VMM/PDMAsyncCompletionFileInternal.h
===================================================================
--- /trunk/src/VBox/VMM/PDMAsyncCompletionFileInternal.h	(revision 29586)
+++ /trunk/src/VBox/VMM/PDMAsyncCompletionFileInternal.h	(revision 29587)
@@ -727,5 +727,5 @@
                           RTFOFF off, PCRTSGSEG paSegments, size_t cSegments,
                           size_t cbWrite);
-int pdmacFileEpCacheFlush(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask);
+int pdmacFileEpCacheFlush(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
 
 RT_C_DECLS_END
