Skip to content

Commit

Permalink
BlockingPool must fit thread_count (elastic#894)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sirdodger authored and fxdgear committed Apr 26, 2019
1 parent dd72153 commit fda9d34
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion elasticsearch/helpers/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fda9d34

Please sign in to comment.