Fix Pool's ongoing count #44
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 encountered an issue where after some time the server would start timing out trying to connect to the mysql server. I'm fairly sure I've narrowed it down to the
ongoingcount inPoolnot always being decremented when connections are dropped or disconnected. As soon as it reaches the PoolConstraints max, and the idle pool has been exhausted, the Pool stops creating any new connections and locks up forever.I don't have a minimal reproduction case, so instead have this long description of why I think this change is correct:
Ongoing count is incremented when:
With my changes the count is now decremented when:
I believe this behavior is correct as long as:
Conn::poolis always set when a connection is taken from the poolConn::poolis never reset while the connection is ongoingConn::poolis always immediately reset when the connection is disconnectedIt seems stable in local testing under high stress, and in production.