thread_pool: fix race condition when shutting down workers #809
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The following backtrace appeared in my error logs:
This signals a problem in thread_pool.rb:250, where the code below lives:
Since at that point
@mutex
is not held,@workers
can and does in fact get modified by threads shutting down. There is a race condition where the worker disappears between the time of check and the time of use because of the code below in thread_pool.rb:111, when the worker is exiting:I have fixed this by
dup
ing the worker threads array inside the critical section and usingeach
to iterate and join all workers.