fix deadlock in imap ssl calling isAlive, r=standard8, bug 711787
authorDavid Bienvenu <bienvenu@nventure.com>
Wed, 04 Jan 2012 08:40:48 -0800
changeset 10343 75840841cc213e66ec6cbad279e3962a29958d3e
parent 10342 7b724a79de0cbb589895552ac9585a0fa79f6819
child 10344 9eda40ffb503df34edc91891b7d22d4bf90a667c
push id402
push userbugzilla@standard8.plus.com
push dateTue, 13 Mar 2012 21:17:18 +0000
treeherdercomm-beta@d080a8ebf16a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstandard8, bug
bugs711787
fix deadlock in imap ssl calling isAlive, r=standard8, bug 711787
mailnews/imap/src/nsImapProtocol.cpp
--- a/mailnews/imap/src/nsImapProtocol.cpp
+++ b/mailnews/imap/src/nsImapProtocol.cpp
@@ -1344,16 +1344,30 @@ nsImapProtocol::ImapThreadMainLoop()
     if (NS_FAILED(rv) && PR_PENDING_INTERRUPT_ERROR == PR_GetError())
     {
       printf("error waiting for monitor\n");
       break;
     }
 
     if (readyToRun && m_runningUrl)
     {
+      if (m_currentServerCommandTagNumber && m_transport)
+      {
+        bool isAlive;
+        rv = m_transport->IsAlive(&isAlive);
+        // if the transport is not alive, and we've ever sent a command with this connection, kill it.
+        // otherwise, we've probably just not finished setting it so don't kill it!
+        if (NS_FAILED(rv) || !isAlive)
+        {
+          // This says we never started running the url, which is the case.
+          m_runningUrl->SetRerunningUrl(false);
+          RetryUrl();
+          return;
+        }
+      }
       //
       // NOTE: Though we cleared m_nextUrlReadyToRun above, it may have been
       //       set by LoadImapUrl, which runs on the main thread.  Because of this,
       //       we must not try to clear m_nextUrlReadyToRun here.
       //
       if (ProcessCurrentURL())
       {
         m_nextUrlReadyToRun = true;
@@ -2186,29 +2200,16 @@ NS_IMETHODIMP nsImapProtocol::CanHandleU
   bool isBusy = false;
   bool isInboxConnection = false;
 
   if (!m_transport)
   {
     // this connection might not be fully set up yet.
     return NS_ERROR_FAILURE;
   }
-  else if (m_currentServerCommandTagNumber != 0)
-  {
-    bool isAlive;
-    rv = m_transport->IsAlive(&isAlive);
-    // if the transport is not alive, and we've ever sent a command with this connection, kill it.
-    // otherwise, we've probably just not finished setting it so don't kill it!
-    if (NS_FAILED(rv) || !isAlive)
-    {
-      MutexAutoUnlock unlock(mLock); // TellThreadToDie gets the lock
-      TellThreadToDie(false);
-      return NS_ERROR_FAILURE;
-    }
-  }
   IsBusy(&isBusy, &isInboxConnection);
   bool inSelectedState = GetServerStateParser().GetIMAPstate() ==
     nsImapServerResponseParser::kFolderSelected;
 
   nsCAutoString curSelectedUrlFolderName;
   nsCAutoString pendingUrlFolderName;
   if (inSelectedState)
     curSelectedUrlFolderName = GetServerStateParser().GetSelectedMailboxName();