Skip to content

Retry listen reconnect when the first attempt fails - #1286

Merged
porsager merged 1 commit into
porsager:masterfrom
vtxe02023274:fix/1285-listen-retry
Nov 1, 2026
Merged

porsager merged 1 commit into
porsager:masterfrom
vtxe02023274:fix/1285-listen-retry

Conversation

@vtxe02023274

Copy link
Copy Markdown
Contributor

Fixes #1285

When the listener connection drops, onclose calls start(name) for each channel and ignores the rejection. If that first reconnect attempt fails (server still restarting, login refused), nothing schedules another attempt, so onlisten is never called again and notifications are lost.

This moves the re-listen into relisten(). On failure it retries after options.backoff(retries) seconds, and stops once end() is called or the channel is unlistened. end() clears pending timers.

Test: new case in tests/listen.js makes the reconnect fail by setting the role to nologin, terminating the backend, then allowing login again. It expects onlisten to run a second time and a notification to arrive. Full CI matrix passes on my fork (Node 18-24 x PostgreSQL 13-18).

@porsager
porsager merged commit 36281a8 into porsager:master Nov 1, 2026
35 of 36 checks passed
@porsager

porsager commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql.listen stops reconnecting if the first reconnect attempt fails (v4 regression)

2 participants