Bug 555124 - Intermittent "ASSERTION: AsyncStatementSpinner not thread-safe: '_mOwningThread.GetThread() == PR_GetCurrentThread()', file .../mozilla/storage/test/test_true_async.cpp, line 162". null out references on the main thread to avoid destruction on the async thread. r=sdwilsh.
authorAndrew Sutherland <asutherland@asutherland.org>
Mon, 29 Mar 2010 10:54:41 -0700
changeset 39986 8901abb7fddbb7965196467282a80c5c14463115
parent 39985 f95c9e28869c0b4b345b61253d6f29ca4a792f7f
child 39987 70698587d13f45adca6bfa4076b5902afb488ebe
push id12485
push userbugmail@asutherland.org
push dateMon, 29 Mar 2010 17:55:39 +0000
treeherdermozilla-central@8901abb7fddb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssdwilsh
bugs555124
milestone1.9.3a4pre
Bug 555124 - Intermittent "ASSERTION: AsyncStatementSpinner not thread-safe: '_mOwningThread.GetThread() == PR_GetCurrentThread()', file .../mozilla/storage/test/test_true_async.cpp, line 162". null out references on the main thread to avoid destruction on the async thread. r=sdwilsh.
storage/src/mozStorageConnection.cpp
--- a/storage/src/mozStorageConnection.cpp
+++ b/storage/src/mozStorageConnection.cpp
@@ -278,16 +278,28 @@ public:
       (void)mCallingThread->Dispatch(this, NS_DISPATCH_NORMAL);
       return NS_OK;
     }
 
     (void)mConnection->internalClose();
     if (mCallbackEvent)
       (void)mCallingThread->Dispatch(mCallbackEvent, NS_DISPATCH_NORMAL);
 
+    // Because we have no guarantee that the invocation of this method on the
+    // asynchronous thread has fully completed (including the Release of the
+    // reference to this object held by that event loop), we need to explicitly
+    // null out our pointers here.  It is possible this object will be destroyed
+    // on the asynchronous thread and if the references are still alive we will
+    // release them on that thread. We definitely do not want that for
+    // mConnection and it's nice to avoid for mCallbackEvent too.  We do not
+    // null out mCallingThread because it is conceivable the async thread might
+    // still be 'in' the object.
+    mConnection = nsnull;
+    mCallbackEvent = nsnull;
+
     return NS_OK;
   }
 private:
   nsCOMPtr<Connection> mConnection;
   nsCOMPtr<nsIEventTarget> mCallingThread;
   nsCOMPtr<nsIRunnable> mCallbackEvent;
 };