From 966841c8d6338cc9b756bfa5f0a3d2d7c3247781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Melis?= Date: Tue, 1 Mar 2011 14:49:02 +0100 Subject: [PATCH] Allow SSL connections to send keep-alive messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Gábor Melis Signed-off-by: Nicolas Sebrecht --- Changelog.draft.rst | 2 ++ offlineimap/imaplibutil.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/Changelog.draft.rst b/Changelog.draft.rst index 44b4a87..8addd4f 100644 --- a/Changelog.draft.rst +++ b/Changelog.draft.rst @@ -23,6 +23,8 @@ Changes Bug Fixes --------- +* Allow SSL connections to send keep-alive messages. + Pending for the next major release ================================== diff --git a/offlineimap/imaplibutil.py b/offlineimap/imaplibutil.py index 69d3983..6752328 100644 --- a/offlineimap/imaplibutil.py +++ b/offlineimap/imaplibutil.py @@ -110,6 +110,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: