porsager / porsager/postgres

Handy helper in node-postgres: allowExitOnIdle

Open
#918 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
8.7k
Forks
374
Avg merge
11d 16h
Merged PRs (30d)
1

Description

Hi.

I recently migrated from node-postgres to postgres.js and ran into the issue that my script would never finish as the connection was still open and therefore block the node event loop.
node-postgres has a config option for this: allowExitOnIdle which they describe like this:

Default behavior is the pool will keep clients open & connected to the backend
until idleTimeoutMillis expire for each client and node will maintain a ref
to the socket on the client, keeping the event loop alive until all clients are closed
after being idle or the pool is manually shutdown with pool.end().

Setting allowExitOnIdle: true in the config will allow the node event loop to exit
as soon as all clients in the pool are idle, even if their socket is still open
to the postgres server. This can be handy in scripts & tests
where you don't want to wait for your clients to go idle before your process exits.

I believe that would be a great feature to have in postgres.js as well :)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the pool and client socket lifecycle in postgres.js, then compare it with node-postgres's allowExitOnIdle behavior described in the issue. Done means an opt-in configuration allows the Node process to exit once all clients are idle, while preserving the existing default behavior; add coverage for the idle and connected cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, postgresql
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.