[PATCH 2/2] imapserver: fix race condition while releasing connection

Nicolas Sebrecht nicolas.s-dev at laposte.net
Sun Jan 18 19:34:22 GMT 2015


Signed-off-by: Nicolas Sebrecht <nicolas.s-dev at laposte.net>
---
 offlineimap/folder/IMAP.py | 12 +++++-------
 offlineimap/imapserver.py  |  2 +-
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index 67748dd..e0c0cc7 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -224,13 +224,11 @@ class IMAPFolder(BaseFolder):
             res_type, response = imapobj.fetch("'%s'"%
                 msgsToFetch, '(FLAGS UID)')
             if res_type != 'OK':
-                raise Exception("restype != 'OK'")
-        except Exception as e:
-            raise OfflineImapError("FETCHING UIDs in folder [%s]%s failed. "
-                "Server responded '[%s] %s' exception: '%s'"% (
-                self.getrepository(), self,
-                res_type, response, str(e)),
-                OfflineImapError.ERROR.FOLDER)
+                raise OfflineImapError("FETCHING UIDs in folder [%s]%s failed. "
+                                       "Server responded '[%s] %s'"% (
+                            self.getrepository(), self,
+                            res_type, response),
+                        OfflineImapError.ERROR.FOLDER)
         finally:
             self.imapserver.releaseconnection(imapobj)
 
diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index bac681e..9622c9a 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -128,8 +128,8 @@ class IMAPServer:
         :param drop_conn: If True, the connection will be released and
            not be reused. This can be used to indicate broken connections."""
 
-        if connection is None: return #noop on bad connection
         self.connectionlock.acquire()
+        if connection is None: return #noop on bad connection
         self.assignedconnections.remove(connection)
         # Don't reuse broken connections
         if connection.Terminate or drop_conn:
-- 
2.2.1





More information about the OfflineIMAP-project mailing list