Fix cluster/pool release of connection #6361
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.
This PR fix a possible resource exhaustion on connection to other node.
I can reproduce this issue on v0.11.1 and this PR fix issue. On 0.12 / master this issue should no longer exists - at least in opensource version. That why I didn't updated CHANGELOG.md.
The issue happen when a load spike cause multiple thread to create new connection on the pool. It may cause total to exceed capacity : code of boundedPool.Get
The later when exceeding connection are returned to the pool, they are discarded (since pool is full) but total is NOT decremented : code of boundedPool.put
At this point with the default value, pool have 3 working connections (== capacity) but total may be larger than this, lets say 6.
Now, if the target node goes down, connection will be marked as unusable which will closed them and remove them from pool. code of boundedPool.MarkUnusable
Here total is decremented, but since is was above capacity we end up with an empty pool (all connections fail/timeout since the target node is down) but total is still above 0. It will be 3 in our example.
Then from now, all call to boundedPool.Get will fail: