Skip to content

Commit 317c848

Browse files
committed
Change BufferUnderflowError to ConnectionError in conn._read_bytes()
Both errors are handled the same way when raised and caught, so this makes sense.
1 parent 9cbe45d commit 317c848

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

kafka/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
from functools import partial
44
from itertools import count
55
import logging
6-
import socket
76
import time
87

98
from kafka.common import (
10-
ErrorMapping, TopicAndPartition, BufferUnderflowError, ConnectionError,
9+
ErrorMapping, TopicAndPartition, ConnectionError,
1110
FailedPayloadsException
1211
)
1312
from kafka.conn import KafkaConnection
@@ -175,7 +174,7 @@ def _send_broker_aware_request(self, payloads, encoder_fn, decoder_fn):
175174
continue
176175
try:
177176
response = conn.recv(requestId)
178-
except (ConnectionError, BufferUnderflowError), e:
177+
except ConnectionError, e:
179178
log.warning("Could not receive response to request [%s] "
180179
"from server %s: %s", request, conn, e)
181180
failed = True

kafka/conn.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import struct
55
from threading import local
66

7-
from kafka.common import BufferUnderflowError
87
from kafka.common import ConnectionError
98

109
log = logging.getLogger("kafka")
@@ -53,8 +52,8 @@ def _read_bytes(self, num_bytes):
5352
log.error('Unable to receive data from Kafka: %s', e)
5453
self._raise_connection_error()
5554
if data == '':
56-
self._dirty = True
57-
raise BufferUnderflowError("Not enough data to read this response")
55+
log.error("Not enough data to read this response")
56+
self._raise_connection_error()
5857
bytes_left -= len(data)
5958
log.debug("Read %d/%d bytes from Kafka", num_bytes - bytes_left, num_bytes)
6059
resp += data

0 commit comments

Comments
 (0)