Skip to content

feat: let pool.query pipeline on a connection that is already working - #3739

Open
nigrosimone wants to merge 6 commits into
brianc:masterfrom
nigrosimone:pool-pipeline-mode
Open

feat: let pool.query pipeline on a connection that is already working#3739
nigrosimone wants to merge 6 commits into
brianc:masterfrom
nigrosimone:pool-pipeline-mode

Conversation

@nigrosimone

@nigrosimone nigrosimone commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

close #3738

Passing pipeline: true to a Pool today changes nothing for pool.query(): every query checks out a connection for itself, so there is never a second query to pipeline behind it.

With this change pool.query() can send a query on a connection that is still waiting for results. The pool opens connection up to max first, then picks the one with the fewest queries in flight, capped by a new maxPipeline option (default 10) and by socket backpressure. max keeps its meaning of number of connections. pool.connect() still checks out a connection nobody else is using, so transactions are not affected. Off by default.

A connection with queries in flight is not idle: idle timeout, maxUses, maxLifetimeSeconds and pool.end() wait for the pending results before closing it.

usage:

const pool = new Pool({ max: 10, pipeline: true, maxPipeline: 100 })
await pool.query('SELECT $1::int', [1]) // same call, can go on a connection already working

Disclaimer: made with the help of Opus 5 and a final check with Fable 5. I have done my best to verify that everything is correct and not AI slopped! tested on my side (patching node modules), seem works

@nigrosimone nigrosimone changed the title Let pool.query pipeline on a connection that is already working feat: let pool.query pipeline on a connection that is already working Aug 10, 2026
@nigrosimone
nigrosimone marked this pull request as ready for review August 10, 2026 06:12
@nigrosimone

Copy link
Copy Markdown
Contributor Author

A good point from @charmander #3738 (comment)

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.

Pipeline mode for Pool

1 participant