diff options
author | Dana Powers <dana.powers@gmail.com> | 2016-08-03 14:45:41 -0700 |
---|---|---|
committer | Dana Powers <dana.powers@gmail.com> | 2016-08-03 14:45:41 -0700 |
commit | b33c446e132c0f63ac2f4b526e20edf0516a28d6 (patch) | |
tree | dbbce502914241ccdc1c58ea8e40c8e70a661cca /kafka/client_async.py | |
parent | 709ee3b59aff8ab205f0e09c33f4ec8391664228 (diff) | |
download | kafka-python-catch_socket_error.tar.gz |
Ignore socket.error when checking for protocol out of sync prior to socket closecatch_socket_error
Diffstat (limited to 'kafka/client_async.py')
-rw-r--r-- | kafka/client_async.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/kafka/client_async.py b/kafka/client_async.py index 6e07ab0..127b3f5 100644 --- a/kafka/client_async.py +++ b/kafka/client_async.py @@ -537,10 +537,13 @@ class KafkaClient(object): # # either way, we can no longer safely use this connection # - # Do a 1-byte read to clear the READ flag, and then close the conn - unexpected_data = key.fileobj.recv(1) - if unexpected_data: # anything other than a 0-byte read means protocol issues - log.warning('Protocol out of sync on %r, closing', conn) + # Do a 1-byte read to check protocol didnt get out of sync, and then close the conn + try: + unexpected_data = key.fileobj.recv(1) + if unexpected_data: # anything other than a 0-byte read means protocol issues + log.warning('Protocol out of sync on %r, closing', conn) + except socket.error: + pass conn.close() continue |