conn: Catch ssl.EOFErrors on Python3.3 so we close the failing conn #1162
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I saw this traceback as a recurring loop in my client which uses KafkaConsumer:
...
File "/usr/lib/python3.5/site-packages/kafka/client_async.py", line 491, in send
if not self._maybe_connect(node_id):
File "/usr/lib/python3.5/site-packages/kafka/client_async.py", line 368, in _maybe_connect
conn.connect()
File "/usr/lib/python3.5/site-packages/kafka/conn.py", line 355, in connect
if self._try_handshake():
File "/usr/lib/python3.5/site-packages/kafka/conn.py", line 420, in _try_handshake
self._sock.do_handshake()
File "/usr/lib64/python3.5/ssl.py", line 996, in do_handshake
self._sslobj.do_handshake()
File "/usr/lib64/python3.5/ssl.py", line 641, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:720)
Based on: https://docs.python.org/3/library/ssl.html:
exception ssl.SSLEOFError
A subclass of SSLError raised when the SSL connection has been terminated
abruptly. Generally, you shouldn’t try to reuse the underlying transport
when this error is encountered.
So start closing the connection if we get EOFError from the connection
instead of just raising the exception up the stack.