Skip to content

Commit fda9d34

Browse files
sirdodgerfxdgear
authored andcommitted
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.
1 parent dd72153 commit fda9d34

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

elasticsearch/helpers/actions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,9 @@ def parallel_bulk(
347347
class BlockingPool(ThreadPool):
348348
def _setup_queues(self):
349349
super(BlockingPool, self)._setup_queues()
350-
self._inqueue = Queue(queue_size)
350+
# The queue must be at least the size of the number of threads to
351+
# prevent hanging when inserting sentinel values during teardown.
352+
self._inqueue = Queue(max(queue_size, thread_count))
351353
self._quick_put = self._inqueue.put
352354

353355
pool = BlockingPool(thread_count)

0 commit comments

Comments
 (0)