Bug 1401459 - always run HttpChannelChild::Release on main thread. r=mayhemer a=gchang
authorShih-Chiang Chien <schien@mozilla.com>
Thu, 11 Jan 2018 10:40:29 +0800
changeset 445677 aba167b6e63f27f9b10ce8805b4e02d8b0a79035
parent 445676 5096a6c3aefd858af15facdd31b53d8f57baf061
child 445678 7151850b2933e3ae6e41435461545db63b6591c9
push id1626
push userarchaeopteryx@coole-files.de
push dateWed, 17 Jan 2018 10:41:52 +0000
treeherdermozilla-release@571ae115f2de [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer, gchang
bugs1401459
milestone58.0
Bug 1401459 - always run HttpChannelChild::Release on main thread. r=mayhemer a=gchang
netwerk/protocol/http/HttpChannelChild.cpp
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -240,16 +240,29 @@ HttpChannelChild::ReleaseMainThreadOnlyR
 //-----------------------------------------------------------------------------
 // HttpChannelChild::nsISupports
 //-----------------------------------------------------------------------------
 
 NS_IMPL_ADDREF(HttpChannelChild)
 
 NS_IMETHODIMP_(MozExternalRefCountType) HttpChannelChild::Release()
 {
+  if (!NS_IsMainThread()) {
+    nsrefcnt count = mRefCnt;
+    nsresult rv = NS_DispatchToMainThread(
+                    NewNonOwningRunnableMethod("HttpChannelChild::Release",
+                                               this,
+                                               &HttpChannelChild::Release));
+
+    // Continue Release procedure if failed to dispatch to main thread.
+    if (!NS_WARN_IF(NS_FAILED(rv))) {
+      return count - 1;
+    }
+  }
+
   nsrefcnt count = --mRefCnt;
   MOZ_ASSERT(int32_t(count) >= 0, "dup release");
   NS_LOG_RELEASE(this, count, "HttpChannelChild");
 
   // Normally we Send_delete in OnStopRequest, but when we need to retain the
   // remote channel for security info IPDL itself holds 1 reference, so we
   // Send_delete when refCnt==1.  But if !mIPCOpen, then there's nobody to send
   // to, so we fall through.