diff options
author | Omar Ghishan <omar.ghishan@rd.io> | 2014-01-07 17:26:09 -0800 |
---|---|---|
committer | Omar Ghishan <omar.ghishan@rd.io> | 2014-01-07 17:35:01 -0800 |
commit | b4c20acf2471a7cee23e4e2b7729a100da6c557b (patch) | |
tree | e2d7c3047a6e852e2c5b23a7ebf83aa4b561f051 /kafka/conn.py | |
parent | e5a5477d346a140abd8bba9e5da2a8f9967ac911 (diff) | |
download | kafka-python-b4c20acf2471a7cee23e4e2b7729a100da6c557b.tar.gz |
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
Diffstat (limited to 'kafka/conn.py')
-rw-r--r-- | kafka/conn.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/kafka/conn.py b/kafka/conn.py index a8d6b1f..4749bdd 100644 --- a/kafka/conn.py +++ b/kafka/conn.py @@ -44,7 +44,8 @@ class KafkaConnection(local): bytes_left = num_bytes resp = '' log.debug("About to read %d bytes from Kafka", num_bytes) - + if self._dirty: + self.reinit() while bytes_left: try: data = self._sock.recv(bytes_left) @@ -52,6 +53,7 @@ class KafkaConnection(local): log.error('Unable to receive data from Kafka: %s', e) self._raise_connection_error() if data == '': + self._dirty = True raise BufferUnderflowError("Not enough data to read this response") bytes_left -= len(data) log.debug("Read %d/%d bytes from Kafka", num_bytes - bytes_left, num_bytes) |