bug: pool never recovers after releasing a reserved connection whose backend was terminated.
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
Hey 👋
Thanks for making JavaScript a better place! 🫶
While working on query cancellation in kysely-postgres-js I stumbled upon this behavior:
- create a pool of 1.
- reserve a connection with
reserve(). - run a long query on it, e.g.
pg_sleep. - terminate the connection's backend in a secondary session via
select pg_terminate_backend(pid). - the inflight query rejects with
CONNECTION_CLOSEDas expected. - release the reserved connection back to the pool with
release(). - run another query on the same pool. it never settles.
- we get an uncaught exception:
TypeError: Cannot read properties of null (reading 'write') at Immediate.nextWrite (.../postgres/src/connection.js:255:22)
The pool discarding the dead connection and using another (existing or new) seems like the wanted behavior in this scenario.
Skipping the release(), allows next queries to run.
Possibly related: #1195, #1186.
Happens everytime when using postgres@3.4.9, Node.js v26.1.0, PostgreSQL 18.4.
Contributor guide
No contributing guide indexed for this repository
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.
Research direction
Reproduce the seven-step scenario with postgres@3.4.9, Node.js v26.1.0, and PostgreSQL 18.4, then inspect postgres/src/connection.js around line 255 and the pool reserve/release path. Done means releasing a reserved connection whose backend was terminated no longer leaves the pool hung or raises the null-write exception, and a subsequent query settles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, postgres, postgresql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100