From 394af562be6c34c2fe31ee6517fc3e36db3b8d15 Mon Sep 17 00:00:00 2001
From: Ehsan Akhgari <ehsan@mozilla.com>
Date: Mon, 5 Jun 2017 16:58:52 -0400
Subject: [PATCH] Bug 1370448 - Start poll watchdog timer off of a runnable
 from the main thread in order to avoid a false positive detected deadlock;
 r=dragana

---
 netwerk/base/nsSocketTransportService2.cpp | 27 +++++++++++++---------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/netwerk/base/nsSocketTransportService2.cpp b/netwerk/base/nsSocketTransportService2.cpp
index 7a91b4c4fbbe8..cb628479657e0 100644
--- a/netwerk/base/nsSocketTransportService2.cpp
+++ b/netwerk/base/nsSocketTransportService2.cpp
@@ -1611,17 +1611,22 @@ nsSocketTransportService::GetSocketConnections(nsTArray<SocketInfo> *data)
 void
 nsSocketTransportService::StartPollWatchdog()
 {
-    MutexAutoLock lock(mLock);
-
-    // Poll can hang sometimes. If we are in shutdown, we are going to start a
-    // watchdog. If we do not exit poll within REPAIR_POLLABLE_EVENT_TIME
-    // signal a pollable event again.
-    MOZ_ASSERT(gIOService->IsNetTearingDown());
-    if (mPolling && !mPollRepairTimer) {
-        mPollRepairTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
-        mPollRepairTimer->Init(this, REPAIR_POLLABLE_EVENT_TIME,
-                               nsITimer::TYPE_REPEATING_SLACK);
-    }
+    // Start off the timer from a runnable off of the main thread in order to
+    // avoid a deadlock, see bug 1370448.
+    RefPtr<nsSocketTransportService> self(this);
+    NS_DispatchToMainThread(NS_NewRunnableFunction([self] {
+         MutexAutoLock lock(self->mLock);
+
+         // Poll can hang sometimes. If we are in shutdown, we are going to start a
+         // watchdog. If we do not exit poll within REPAIR_POLLABLE_EVENT_TIME
+         // signal a pollable event again.
+         MOZ_ASSERT(gIOService->IsNetTearingDown());
+         if (self->mPolling && !self->mPollRepairTimer) {
+             self->mPollRepairTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
+             self->mPollRepairTimer->Init(self, REPAIR_POLLABLE_EVENT_TIME,
+                                          nsITimer::TYPE_REPEATING_SLACK);
+         }
+    }));
 }
 
 void
-- 
GitLab