Skip to content

Commit 7b9322f

Browse files
author
Dana Powers
committed
Remove duplicate error handling blocks by moving empty response check into try block in conn.recv
1 parent 472f287 commit 7b9322f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

kafka/conn.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,20 @@ def _read_bytes(self, num_bytes):
8585
self.reinit()
8686

8787
while bytes_left:
88+
8889
try:
8990
data = self._sock.recv(min(bytes_left, 4096))
91+
92+
# Receiving empty string from recv signals
93+
# that the socket is in error. we will never get
94+
# more data from this socket
95+
if data == '':
96+
raise socket.error('Not enough data to read message -- did server kill socket?')
97+
9098
except socket.error:
9199
log.exception('Unable to receive data from Kafka')
92100
self._raise_connection_error()
93101

94-
if data == '':
95-
log.error("Not enough data to read this response")
96-
self._raise_connection_error()
97-
98102
bytes_left -= len(data)
99103
log.debug("Read %d/%d bytes from Kafka", num_bytes - bytes_left, num_bytes)
100104
responses.append(data)

0 commit comments

Comments
 (0)