fix deadlock in imap ssl calling isAlive, r+a=standard8, bug 711787
authorDavid Bienvenu <bienvenu@nventure.com>
Wed, 04 Jan 2012 08:40:48 -0800
changeset 10106 df426b0ca04312d90354297ad4e483b9588066d0
parent 10105 1bfd207d1339c3f5baa2b2cd72b152189d67a25a
child 10107 9f72fdf1b86067467ee9aee70067599f49117291
push idunknown
push userunknown
push dateunknown
bugs711787
fix deadlock in imap ssl calling isAlive, r+a=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 = PR_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(PR_FALSE);
-      return NS_ERROR_FAILURE;
-    }
-  }
   IsBusy(&isBusy, &isInboxConnection);
   bool inSelectedState = GetServerStateParser().GetIMAPstate() ==
     nsImapServerResponseParser::kFolderSelected;
 
   nsCAutoString curSelectedUrlFolderName;
   nsCAutoString pendingUrlFolderName;
   if (inSelectedState)
     curSelectedUrlFolderName = GetServerStateParser().GetSelectedMailboxName();