[PATCH] Allow SSL connections to send keep-alive messages

Sebastian Spaeth Sebastian at SSpaeth.de
Tue Mar 1 13:49:02 GMT 2011


From: Gábor Melis <mega at retes.hu>

This seems to prevent mysterious hangs with SSL imap servers (especially
gmail?) and does not harm in any case. So let us enable keep-alive
messages for ssl connections.
Our thread pool should be made more robust against closed SSL
connections (which do not always seem to raise Exceptions), and not
deadlock while waiting for resources or data that will never arrive.

Reviewed-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
Signed-off-by: Gábor Melis <mega at retes.hu>
---
 offlineimap/imaplibutil.py |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/offlineimap/imaplibutil.py b/offlineimap/imaplibutil.py
index cf82996..7bd446a 100644
--- a/offlineimap/imaplibutil.py
+++ b/offlineimap/imaplibutil.py
@@ -111,6 +111,10 @@ class WrappedIMAP4_SSL(IMAP4_SSL):
             # FIXME
             raise socket.error(last_error)
 
+        # Allow sending of keep-alive message seems to prevent some servers
+        # from closing SSL on us leading to deadlocks
+        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
+
         #connected to socket, now wrap it in SSL
         try:
             if self._cacertfile:
-- 
1.7.1





More information about the OfflineIMAP-project mailing list