Connection reconnect rejects the next query with a stale ErrorResponse from before the socket closed
Maintainers usually reply within 7 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 62/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, nodejs, postgresql
- Domain
- databases
Research direction
Start in src/connection.js, where connect() and closed() reset buffers and timers but leave query, results and errorResponse set. Reproduce with max: 1, a TCP proxy that drops the ReadyForQuery after an ErrorResponse, then a second query on the same connection. Done when the query after reconnect returns 1 instead of the stale error, and a regression test covers it. The reporter offers to send a PR, so check with them before starting.
Written by the indexing model from the issue text.
Description
Version: 3.4.9 (also present on master as of 2026-10)
What happens
If the server (or a pooler such as pgbouncer) sends an ErrorResponse and then closes the socket before the ReadyForQuery, the connection object keeps query and errorResponse set. closed() and connect() reset buffers and timers but not these. When the same connection object connects again, the startup ReadyForQuery sees the old errorResponse, calls errored(errorResponse) and rejects initial, the first query on the new socket, with the old error. This can happen any time later; we saw it 90 minutes after a pgbouncer outage. The stack of the error points to the query that originally failed, not the one that was rejected.
Reproduction (TCP proxy between client and server)
max: 1. Runsql`select 1/0`.- The proxy forwards the
Emessage, drops theZbehind it, and closes both sockets. - Run
sql`select 1`. It rejects withdivision by zeroinstead of returning 1.
Fix we apply locally (at the top of connect() in src/connection.js)
query = results = errorResponse = null
result = new Result()
Happy to open a PR with the fix and a test.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 389
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from porsager/postgres
-
sql.end() never resolves when a reserved connection is released after end() was calledPossibly taken @whoekage claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 7 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 7 days
-
Cancelled query leaves stale row index; next query on the connection returns leading empty slotsPossibly taken @pislm claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 7 days
-
Reconnect after a close with a pending write never sends StartupMessage: stale nextWriteTimer/chunk make every statement fail CONNECT_TIMEOUTPossibly taken @Vengron claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 7 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 7 days
All issues in porsager/postgres
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
keyxmakerx/Chronicle#1469 ·
Maintainers usually reply within 1 day
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
suradet-ps/codeframe#40 ·
Maintainers usually reply within 1 day
-
data
Difficulty 1/5 Under an hour Newbie friendliness 74/100
gaseous-project/hasheous#637 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
gramps-project/gramps-web#1549 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100