[PATCH] Drop all connections when a sync failed

Sebastian Spaeth Sebastian at SSpaeth.de
Wed Apr 27 10:44:24 BST 2011

in accounts.sync() we would holdordropconnections() after each sync. But
depending on the repository configuration that might imply that
offlineimap tries to keep the same connections. But when a sync failed,
e.g. after a user had his computer suspended, it might be that our
connections that we have are worthless. So definitely drop them after a
failed sync.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
As the user reported that a gmail account failed up to 3 refresh times
after a suspend (which would correspond to our lifetime of a connection
that we try to keep open between syncs), I suspect that we never
definitely close/drop connections after a sync failed. This patch should
help with that by definitely dropping all connections when a sync raises
an Exception.

 offlineimap/accounts.py |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py
index 7edfa37..1867b07 100644
--- a/offlineimap/accounts.py
+++ b/offlineimap/accounts.py
@@ -265,7 +265,14 @@ class SyncableAccount(Account):
-        finally:
+        except:
+            #error while syncing. Drop all connections that we have, they
+            #might be bogus by now (e.g. after suspend)
+            localrepos.dropconnections()
+            remoterepos.dropconnections()
+            raise
+        else:
+            # sync went fine. Hold or drop depending on config

More information about the OfflineIMAP-project mailing list