Add opt-in reject_throttle: pace connection opens after establishment failures#1180
Open
fabio-vapi wants to merge 1 commit into
Open
Add opt-in reject_throttle: pace connection opens after establishment failures#1180fabio-vapi wants to merge 1 commit into
reject_throttle: pace connection opens after establishment failures#1180fabio-vapi wants to merge 1 commit into
Conversation
fabio-vapi
marked this pull request as ready for review
July 16, 2026 15:32
fabio-vapi
force-pushed
the
reject-throttle
branch
from
July 16, 2026 20:09
25949aa to
6469acb
Compare
…lures Opt-in (default off; off is behaviourally identical to today). When a connection fails to ESTABLISH, the pool otherwise retries every connection immediately and in lockstep — stampeding a server that is already rejecting connections. With reject_throttle enabled the pool keeps a single failed connection as the lone prober (retrying with backoff), blocks the rest, and on each prober handshake success admits an exponentially growing batch of waiters (slow-start, capped at `max`), disengaging once the backlog drains. This complements the existing per-connection `backoff`: backoff only delays each retry, and since its counter is pool-shared every connection waits the same delay and then fires together — a delayed herd. reject_throttle instead keeps exactly one attempt in flight during an outage. It governs only the clean-close establishment-reconnect path (`if (initial) return reconnect()`); error-close (RST) and connect-timeout still reject as before. Tests in tests/reject_throttle.js (21 cases): option plumbing, throttle-vs-herd, single prober, ramp collapse, recovery and disengagement (including large backlogs and max:1), drop-path intact via max_lifetime, and boundaries (RST reject, connect_timeout, off == vanilla).
fabio-vapi
force-pushed
the
reject-throttle
branch
from
July 16, 2026 22:04
6469acb to
0ecb7e7
Compare
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.
Fixes #1179.
Adds an opt-in
reject_throttle(default off; when off, behaviour is identical to today) that fixes the establishment-failure herd described in the issue.What it does
backoffcurve instead of retrying immediately. (Todayclosed()'sif (initial) return reconnect()returns beforeclosedTime/delayare assigned, soreconnect()computessetTimeout(connect, 0)— a tight loop.)1 → 2 → 4 → … → max); a failed admission collapses the ramp back to 1. Once the backlog drains, the breaker disengages back to baseline. Liveness is the prober's own retry — no timers.It complements the existing
backoffrather than duplicating it:backoffonly delays each retry, and because its counter lives on the shared pool object, every connection waits the same delay and then fires together — a delayed herd.reject_throttlekeeps exactly one attempt in flight during an outage and ramps back up on recovery.It governs only the clean-close establishment-reconnect path; error-close (RST) and connect-timeout still reject exactly as before, so it never masks a hard failure. With it enabled, the issue's reproduction drops from ~12.5k attempts/sec to single digits and recovers via slow-start once the endpoint accepts again.
Changes
src/index.js— thereject_throttleoption andshared.throttlestate; the gate (throttleAllows) at the threeclosed → connectingpromotion sites;throttleAdmit(slow-start admission + disengage) inonopen;requeue.src/connection.js— establishment-failure routing (reconnect_with_reject_throttle→prober_reconnect|stand_down),backOffOnError, andthrottle_on_successatReadyForQuery.Tests
tests/reject_throttle.js— 21 cases: option plumbing, throttle-vs-herd, single prober, slow-start recovery and disengagement (including large backlogs andmax: 1), the drop path staying intact viamax_lifetime, and the boundaries (RST reject, connect_timeout,off == vanilla). Wired intotest:esm; kept as a separate file for reviewability — happy to fold intotests/index.jsif you'd prefer.