You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The local retries counter in src/connection.js is read but never incremented — only options.shared.retries (the backoff counter) is. With ≥2 hosts, retries stays 0 forever, so:
target_session_attrs: 'prefer-standby' with the standby down: tryNext()
(L796) never runs
out of hosts, so it terminates every primary connection and retries the dead standby forever.
All hosts down: error()
(L382) always sees
"another host to try" and swallows every connect error — queries hang forever, even with connect_timeout.
With a primary on localhost:5432 and nothing on 5431 — both cases hang forever on 3.4.9:
// expected: connects to the primaryawaitpostgres({host: ['localhost','localhost'],port: [5431,5432],target_session_attrs: 'prefer-standby',connect_timeout: 5})`select 1`// expected: rejects after both hosts failawaitpostgres({host: ['localhost','localhost'],port: [5431,5430],connect_timeout: 5})`select 1`
Purposed Fix
Reset retries per connection cycle, increment per failed attempt, and surface the error once
every host is tried. prefer-standby requires a standby only on the first pass over the host list
and accepts any server on a second pass (like libpq). Route connect timeouts through error()
so they fail over like refused connections (fixes #988).
Bug
The local
retriescounter insrc/connection.jsis read but never incremented — onlyoptions.shared.retries(the backoff counter) is. With ≥2 hosts,retriesstays0forever, so:target_session_attrs: 'prefer-standby'with the standby down:tryNext()(L796) never runs
out of hosts, so it terminates every primary connection and retries the dead standby forever.
error()(L382) always sees
"another host to try" and swallows every connect error — queries hang forever, even with
connect_timeout.connectTimedOut()callserrored()directly, bypassing failover, soCONNECT_TIMEOUTrejects instead of trying the next host whileECONNREFUSEDfails over.Repro
With a primary on
localhost:5432and nothing on5431— both cases hang forever on 3.4.9:Purposed Fix
Reset
retriesper connection cycle, increment per failed attempt, and surface the error onceevery host is tried. prefer-standby requires a standby only on the first pass over the host list
and accepts any server on a second pass (like libpq). Route connect timeouts through
error()so they fail over like refused connections (fixes #988).