Bug 1026951 - Fix: NS_IsMainThread() (OnStateStop should only be called on the main thread.) assertion failure. r=sworkman, a=sledru
authorMichal Novotny <michal.novotny@gmail.com>
Thu, 14 Aug 2014 05:45:00 -0400
changeset 217519 e7bb9c0cbb403cbbcfd4b42940b3df3c7fe17d04
parent 217518 9b8c0def997a7b945d3b870125d34fd7fdabdaaf
child 217520 bf59c8cff7ad23de4185f17dd39766e15870475c
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssworkman, sledru
bugs1026951
milestone33.0a2
Bug 1026951 - Fix: NS_IsMainThread() (OnStateStop should only be called on the main thread.) assertion failure. r=sworkman, a=sledru
netwerk/base/src/nsInputStreamPump.cpp
--- a/netwerk/base/src/nsInputStreamPump.cpp
+++ b/netwerk/base/src/nsInputStreamPump.cpp
@@ -464,16 +464,26 @@ nsInputStreamPump::OnInputStreamReady(ns
         if (nextState == STATE_STOP && !NS_IsMainThread()) {
             mRetargeting = true;
         }
 
         // Unset mProcessingCallbacks here (while we have lock) so our own call to
         // EnsureWaiting isn't blocked by it.
         mProcessingCallbacks = false;
 
+        // We must break the loop when we're switching event delivery to another
+        // thread and the input stream pump is suspended, otherwise
+        // OnStateStop() might be called off the main thread. See bug 1026951
+        // comment #107 for the exact scenario.
+        if (mSuspendCount && mRetargeting) {
+            mState = nextState;
+            mWaitingForInputStreamReady = false;
+            break;
+        }
+
         // Wait asynchronously if there is still data to transfer, or we're
         // switching event delivery to another thread.
         if (!mSuspendCount && (stillTransferring || mRetargeting)) {
             mState = nextState;
             mWaitingForInputStreamReady = false;
             nsresult rv = EnsureWaiting();
             if (NS_SUCCEEDED(rv))
                 break;