Fixes #23483 Add lock, add notifyWaitingThreads call for better max pool size logic. #24879
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.
Fixes #23483 Add lock logic between 2 methods, add notifyWaitingThreads call for better max pool size logic.
Add lock, add notifyWaitingThreads call for better max pool size logic. No longer getResources while the pool is being resized. And inform waiting threads when resources are marked as failed.
See my analysis in #23483 for more information. Short version: getResource takes a connection from the pool, and resizes the pool when needed, while in the meantime another thread returns a resource to the pool, causing the resizePoolAndGetNewResource method to make the pool size too large. And in case of failing connections are being returned, the waiting threads are not informed, while they could ask for a fresh new connection from the pool.
Without the changes in ConnectionPool you should be able to reproduce the issues with the unit test. It might be needed to run the test several times, or increase the number of tasks in the test itself.