diff options
author | Dana Powers <dana.powers@gmail.com> | 2018-02-08 09:40:49 -0800 |
---|---|---|
committer | Dana Powers <dana.powers@gmail.com> | 2018-02-08 09:40:49 -0800 |
commit | 52eae4a14268a57786eabd26b2022163dc5dc5e5 (patch) | |
tree | ff11cdf2eb24c41e764dadfecfcfcb3f79d884c5 /kafka | |
parent | 68068cac13c4cacbe3122cdcba39aa0d3c060b99 (diff) | |
download | kafka-python-threadsafe_pending_responses.tar.gz |
Fix pending completion IndexError bug caused by multiple threadsthreadsafe_pending_responses
Diffstat (limited to 'kafka')
-rw-r--r-- | kafka/client_async.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/kafka/client_async.py b/kafka/client_async.py index 4962d9f..24a5bef 100644 --- a/kafka/client_async.py +++ b/kafka/client_async.py @@ -665,8 +665,14 @@ class KafkaClient(object): def _fire_pending_completed_requests(self): responses = [] - while self._pending_completion: - response, future = self._pending_completion.popleft() + while True: + try: + # We rely on deque.popleft remaining threadsafe + # to allow both the heartbeat thread and the main thread + # to process responses + response, future = self._pending_completion.popleft() + except IndexError: + break future.success(response) responses.append(response) return responses |