Index: /trunk/src/VBox/Devices/Audio/DrvHostPulseAudio.cpp
===================================================================
--- /trunk/src/VBox/Devices/Audio/DrvHostPulseAudio.cpp	(revision 58589)
+++ /trunk/src/VBox/Devices/Audio/DrvHostPulseAudio.cpp	(revision 58590)
@@ -216,11 +216,11 @@
     {
         uint64_t u64StartMs = RTTimeMilliTS();
-        uint64_t u64ElapsedMs;
-
         while (pa_operation_get_state(pOP) == PA_OPERATION_RUNNING)
         {
-            pa_threaded_mainloop_wait(g_pMainLoop);
-
-            u64ElapsedMs = RTTimeMilliTS() - u64StartMs;
+            if (!g_fAbortMainLoop)
+                pa_threaded_mainloop_wait(g_pMainLoop);
+            g_fAbortMainLoop = false;
+
+            uint64_t u64ElapsedMs = RTTimeMilliTS() - u64StartMs;
             if (u64ElapsedMs >= cMsTimeout)
             {
@@ -317,5 +317,5 @@
         drvHostPulseAudioAbortMainLoop();
     else
-         drvHostPulseAudioError(pStrm->pDrv, "Failed to finish stream operation");
+        drvHostPulseAudioError(pStrm->pDrv, "Failed to finish stream operation");
 }
 
@@ -400,11 +400,11 @@
 
         /* Wait until the stream is ready. */
-        pa_stream_state_t sstate;
         for (;;)
         {
             if (!g_fAbortMainLoop)
                 pa_threaded_mainloop_wait(g_pMainLoop);
-
-            sstate = pa_stream_get_state(pStream);
+            g_fAbortMainLoop = false;
+
+            pa_stream_state_t sstate = pa_stream_get_state(pStream);
             if (sstate == PA_STREAM_READY)
                 break;
@@ -433,15 +433,15 @@
                      pBufAttr->maxlength, pBufAttr->tlength, pBufAttr->prebuf, pBufAttr->minreq));
 
-        pa_threaded_mainloop_unlock(g_pMainLoop);
     }
     while (0);
 
+    if (   RT_FAILURE(rc)
+        && pStream)
+        pa_stream_disconnect(pStream);
+
+    pa_threaded_mainloop_unlock(g_pMainLoop);
+
     if (RT_FAILURE(rc))
     {
-        if (pStream)
-            pa_stream_disconnect(pStream);
-
-        pa_threaded_mainloop_unlock(g_pMainLoop);
-
         if (pStream)
             pa_stream_unref(pStream);
@@ -512,9 +512,9 @@
         for (;;)
         {
-            pa_context_state_t cstate;
             if (!g_fAbortMainLoop)
                 pa_threaded_mainloop_wait(g_pMainLoop);
-
-            cstate = pa_context_get_state(g_pContext);
+            g_fAbortMainLoop = false;
+
+            pa_context_state_t cstate = pa_context_get_state(g_pContext);
             if (cstate == PA_CONTEXT_READY)
                 break;
