Repository navigation
Bound reconnects when connections close while fetching types - #1279
Merged
Merged
Conversation
Owner
|
Very nice - Thank you ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
On 4.0.0 a connection that closes while the pool's array and domain types query runs is replaced at once, without
backoffand withoutconnect_timeout. When the peer closes each new connection at that query, a query waiting for a connection never settles, and the pool opens new connections, each a full startup, as fast as the server takes them for as long as the peer keeps closing. This finishes #1193: v4 bounds a close during startup, but by the time the types query runsopened()has already resetretriesandfailingSince, and the close goes throughonclose(), which only grows the pool again.This change counts a connection that closes while it loads types as a failed attempt, as
failed()counts a failed startup, sobackoffpaces the reconnects and the waiting queries reject withCONNECTION_CLOSEDonceconnect_timeouthas passed, or at once while the pool is ending. The retry state is reset once a connection can serve, which is when the types are in rather than when its startup completes, and after a failed attempt the pool waits for a connection that is still loading types rather than opening another beside it. Withconnect_timeoutdisabled (0, null or false), such an attempt is retried withbackofffor as long as it takes, as the option says, and so is a startup that closes or is refused for too many connections, which before failed the waiting queries at once.The existing test for a backend that dies while fetching array types waited for
typarray, which v4's types query does not contain, so it never reached that query, and it now waits forpg_type. The tests attests/connection.js:566and:696on master also wait fortyparrayand so never reach the types query either, and this changes neither.Reproduction
Against PostgreSQL 17, with a relay in front of it that closes each connection when the types query arrives:
On 4.0.0:
With this change: