From fda9d3429c50e70c702de54b775afe629f2a1ed2 Mon Sep 17 00:00:00 2001 From: Christopher Lee Date: Fri, 26 Apr 2019 10:57:11 -0700 Subject: [PATCH] BlockingPool must fit thread_count (#894) queue_size must be greater than or equal to thread_count, or else the main thread can hang trying to acquire a lock to write sentinel values to the queue during teardown. --- elasticsearch/helpers/actions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/elasticsearch/helpers/actions.py b/elasticsearch/helpers/actions.py index cf7f16aa..bfdf6418 100644 --- a/elasticsearch/helpers/actions.py +++ b/elasticsearch/helpers/actions.py @@ -347,7 +347,9 @@ def parallel_bulk( class BlockingPool(ThreadPool): def _setup_queues(self): super(BlockingPool, self)._setup_queues() - self._inqueue = Queue(queue_size) + # The queue must be at least the size of the number of threads to + # prevent hanging when inserting sentinel values during teardown. + self._inqueue = Queue(max(queue_size, thread_count)) self._quick_put = self._inqueue.put pool = BlockingPool(thread_count)