From a795faa4eecc580c0017f99ce8ee25c75174f4d4 Mon Sep 17 00:00:00 2001 From: Alexander Sibiryakov Date: Wed, 15 Jul 2020 15:25:31 +0200 Subject: [PATCH 1/2] handling OSError --- kafka/conn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kafka/conn.py b/kafka/conn.py index c383123ca..836744997 100644 --- a/kafka/conn.py +++ b/kafka/conn.py @@ -507,7 +507,7 @@ def _try_handshake(self): # old ssl in python2.6 will swallow all SSLErrors here... except (SSLWantReadError, SSLWantWriteError): pass - except (SSLZeroReturnError, ConnectionError, TimeoutError, SSLEOFError): + except (SSLZeroReturnError, ConnectionError, TimeoutError, SSLEOFError, OSError): log.warning('SSL connection closed by server during handshake.') self.close(Errors.KafkaConnectionError('SSL connection closed by server during handshake')) # Other SSLErrors will be raised to user From 5b833354167ddcbffea0ed7ed43e478db2cb1b5e Mon Sep 17 00:00:00 2001 From: Alexander Sibiryakov Date: Wed, 15 Jul 2020 15:37:37 +0200 Subject: [PATCH 2/2] better error output --- kafka/conn.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kafka/conn.py b/kafka/conn.py index 836744997..8d676953f 100644 --- a/kafka/conn.py +++ b/kafka/conn.py @@ -507,7 +507,8 @@ def _try_handshake(self): # old ssl in python2.6 will swallow all SSLErrors here... except (SSLWantReadError, SSLWantWriteError): pass - except (SSLZeroReturnError, ConnectionError, TimeoutError, SSLEOFError, OSError): + except (SSLZeroReturnError, ConnectionError, TimeoutError, SSLEOFError, ssl.SSLError, OSError) as e: + log.exception(e) log.warning('SSL connection closed by server during handshake.') self.close(Errors.KafkaConnectionError('SSL connection closed by server during handshake')) # Other SSLErrors will be raised to user