summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDana Powers <dana.powers@gmail.com>2016-08-03 14:45:41 -0700
committerDana Powers <dana.powers@gmail.com>2016-08-03 14:45:41 -0700
commitb33c446e132c0f63ac2f4b526e20edf0516a28d6 (patch)
treedbbce502914241ccdc1c58ea8e40c8e70a661cca
parent709ee3b59aff8ab205f0e09c33f4ec8391664228 (diff)
downloadkafka-python-catch_socket_error.tar.gz
Ignore socket.error when checking for protocol out of sync prior to socket closecatch_socket_error
-rw-r--r--kafka/client_async.py11
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