Skip to content

Commit 0e753e6

Browse files
authored
Ignore socket.error when checking for protocol out of sync prior to socket close (#792)
1 parent 709ee3b commit 0e753e6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

kafka/client_async.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,13 @@ def _poll(self, timeout, sleep=True):
537537
#
538538
# either way, we can no longer safely use this connection
539539
#
540-
# Do a 1-byte read to clear the READ flag, and then close the conn
541-
unexpected_data = key.fileobj.recv(1)
542-
if unexpected_data: # anything other than a 0-byte read means protocol issues
543-
log.warning('Protocol out of sync on %r, closing', conn)
540+
# Do a 1-byte read to check protocol didnt get out of sync, and then close the conn
541+
try:
542+
unexpected_data = key.fileobj.recv(1)
543+
if unexpected_data: # anything other than a 0-byte read means protocol issues
544+
log.warning('Protocol out of sync on %r, closing', conn)
545+
except socket.error:
546+
pass
544547
conn.close()
545548
continue
546549

0 commit comments

Comments
 (0)