diff options
author | Dana Powers <dana.powers@gmail.com> | 2016-11-18 09:07:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-18 09:07:53 -0800 |
commit | f71cfc4607c0295a8e131576f8619c9f8ff8f66f (patch) | |
tree | 590ccc083b914127d1dbc59c439c07e2f94c76bf | |
parent | 57ea7e81dc00065825c1586af7fe3cc9609d1f6b (diff) | |
download | kafka-python-f71cfc4607c0295a8e131576f8619c9f8ff8f66f.tar.gz |
Always check for request timeouts (#887)
* Check for requests that timeout without causing a socket read/write event
-rw-r--r-- | kafka/client_async.py | 8 | ||||
-rw-r--r-- | kafka/conn.py | 8 |
2 files changed, 12 insertions, 4 deletions
diff --git a/kafka/client_async.py b/kafka/client_async.py index 03a2f00..bd9bf2e 100644 --- a/kafka/client_async.py +++ b/kafka/client_async.py @@ -578,6 +578,14 @@ class KafkaClient(object): if response: responses.append(response) + for conn in six.itervalues(self._conns): + if conn.requests_timed_out(): + log.warning('%s timed out after %s ms. Closing connection.', + conn, conn.config['request_timeout_ms']) + conn.close(error=Errors.RequestTimedOutError( + 'Request timed out after %s ms' % + conn.config['request_timeout_ms'])) + if self._sensors: self._sensors.io_time.record((time.time() - end_select) * 1000000000) return responses diff --git a/kafka/conn.py b/kafka/conn.py index b451895..21607d9 100644 --- a/kafka/conn.py +++ b/kafka/conn.py @@ -575,15 +575,15 @@ class BrokerConnection(object): log.warning('%s: No in-flight-requests to recv', self) return None - elif self._requests_timed_out(): + response = self._recv() + if not response and self.requests_timed_out(): log.warning('%s timed out after %s ms. Closing connection.', self, self.config['request_timeout_ms']) self.close(error=Errors.RequestTimedOutError( 'Request timed out after %s ms' % self.config['request_timeout_ms'])) return None - - return self._recv() + return response def _recv(self): # Not receiving is the state of reading the payload header @@ -719,7 +719,7 @@ class BrokerConnection(object): self._processing = False return response - def _requests_timed_out(self): + def requests_timed_out(self): if self.in_flight_requests: oldest_at = self.in_flight_requests[0].timestamp timeout = self.config['request_timeout_ms'] / 1000.0 |