[PATCH 5/5] IMAP IDLE cleanup(5): Really discard connections when they are dropped

Sebastian Spaeth Sebastian at SSpaeth.de
Mon Sep 12 08:37:57 UTC 2011


Finally, actually discard dropped connections when we detect them as an
imapobj.abort() has been thrown. In this case, invoke releaseconnection
with drop_conn=True.

We don't need the self.aborted attribute to get signified of dropped
connections. An Execption during the noop will do.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/imapserver.py |   32 +++++++++++++++-----------------
 1 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index f4fc7fa..b9b30a6 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -505,18 +505,13 @@ class IdleThread(object):
             connections, or c) the standard imaplib IDLE timeout of 29
             minutes kicks in."""
             result, cb_arg, exc_data = args
-            if exc_data is None:
-                if not self.stop_sig.isSet():
-                    self.needsync = True
-                    self.stop_sig.set()
-            else:
-                # We got an "abort" signal.
-                self.imapaborted = True
-                self.stop()
+            if exc_data is None and not self.stop_sig.isSet():
+                # No Exception, and we are not supposed to stop:
+                self.needsync = True
+            self.stop_sig.set() # continue to sync
 
         while not self.stop_sig.isSet():
             self.needsync = False
-            self.imapaborted = False
 
             success = False # successfully selected FOLDER?
             while not success:
@@ -527,7 +522,7 @@ class IdleThread(object):
                     if e.severity == OfflineImapError.ERROR.FOLDER_RETRY:
                         # Connection closed, release connection and retry
                         self.ui.error(e, exc_info()[2])
-                        self.parent.releaseconnection(imapobj)
+                        self.parent.releaseconnection(imapobj, True)
                     else:
                         raise e
                 else:
@@ -539,13 +534,16 @@ class IdleThread(object):
                     "Sleep until next refresh cycle." % imapobj.identifier)
                 imapobj.noop()
             self.stop_sig.wait() # self.stop() or IDLE callback are invoked
-            if self.stop_sig.isSet():
-                # Can't NOOP on a bad connection.
-                if not self.imapaborted:
-                    imapobj.noop()
-                    # We don't do event.clear() so that we'll fall out
-                    # of the loop next time around.
-            self.parent.releaseconnection(imapobj)
+            try:
+                # End IDLE mode with noop, imapobj can point to a dropped conn.
+                imapobj.noop()
+            except imapobj.abort():
+                self.ui.warn('Attempting NOOP on dropped connection %s' % \
+                                 imapobj.identifier)
+                self.parent.releaseconnection(imapobj, True)
+            else:
+                self.parent.releaseconnection(imapobj)
+
             if self.needsync:
                 # here not via self.stop, but because IDLE responded. Do
                 # another round and invoke actual syncing.
-- 
1.7.4.1




More information about the OfflineIMAP-project mailing list