From b33c446e132c0f63ac2f4b526e20edf0516a28d6 Mon Sep 17 00:00:00 2001 From: Dana Powers Date: Wed, 3 Aug 2016 14:45:41 -0700 Subject: Ignore socket.error when checking for protocol out of sync prior to socket close --- kafka/client_async.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'kafka/client_async.py') 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 -- cgit v1.2.1