fix race condition in ScalingThreadPoolExecutor
#13360
Merged
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.
I introduced
ScalingThreadPoolExecutor
previously to provide an autoscaling thread pool, used to prevent interrupts from corrupting the realtime Lucene index.There is a race condition as the logic relied on
_executor.getPoolSize()
and_executor.getActiveCount()
, and using the latter could lag the 'real' count of currently idle threads. In this case, the task would be queued and not executed. This PR changes the implementation slightly to track idle threads via overriding the two methods that may be used by ThreadPoolExecutor.getTask(), which is always executed by an idle thread to pick up the next task.In theory the bug could cause sporadic timeouts for searches against the realtime Lucene index, though it is hard to reproduce. I came across this bug trying to use
ScalingThreadPoolExecutor
for another feature.For testing, unit tests should cover this logic. The race condition is easily reproducible when the added unit test is used against the old implementation.
suggested tag:
bugfix