Skip to content

Commit b4c20ac

Browse files
committed
Handle dirty flag in conn.recv()
* If the connection is dirty, reinit * If we get a BufferUnderflowError, the server could have gone away, so mark it dirty
1 parent e5a5477 commit b4c20ac

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kafka/conn.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ def _read_bytes(self, num_bytes):
4444
bytes_left = num_bytes
4545
resp = ''
4646
log.debug("About to read %d bytes from Kafka", num_bytes)
47-
47+
if self._dirty:
48+
self.reinit()
4849
while bytes_left:
4950
try:
5051
data = self._sock.recv(bytes_left)
5152
except socket.error, e:
5253
log.error('Unable to receive data from Kafka: %s', e)
5354
self._raise_connection_error()
5455
if data == '':
56+
self._dirty = True
5557
raise BufferUnderflowError("Not enough data to read this response")
5658
bytes_left -= len(data)
5759
log.debug("Read %d/%d bytes from Kafka", num_bytes - bytes_left, num_bytes)

0 commit comments

Comments
 (0)