question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pool.query(new QueryStream(...)) unexpected behaviour

See original GitHub issue

Hi, if I use the query method on pg.Pool with a query object that implements sumbit (i.e. pg-query-stream or pg-cursor) like this:

import { Pool } from "pg";
import QueryStream = require("pg-query-stream");
const pool = new Pool();
// ...
const query = new QueryStream("SELECT * FROM ...");
const q = pool.query(query);
console.log(q); // Promise { <pending>, ...
await q; //!

the returned promise never resolves and the pool never releases the used client

I could ignore the return value and continue with the result, e.g.

for await (const row in query) { ...process row...}

but the client leak is a problem

furthermore, the typescript definition is plain wrong:

export class Pool extends events.EventEmitter {
// ...
    query<T extends Submittable>(queryStream: T): T;
// ...
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
aleclarsoncommented, Sep 7, 2022

I’ve submitted a PR that fixes this 👀

#2810

1reaction
brianccommented, Nov 27, 2019

yeah that sounds like a problem - I’ll definitely look at this. For now I think a workaround you can do is

const client = await pool.connect()
const query = new QueryStream('SELECT *')
const stream = client.query(query)
for await (const row of stream) {

}
client.release()

Sorry for the hassle - i’ll get this fixed

Read more comments on GitHub >

github_iconTop Results From Across the Web

postgres query takes longer when streaming in node
This is how I query my data in Node : const {Pool} = require('pg'); const QueryStream = require('pg-query-stream'); const CSVStream ...
Read more >
Serverless SQL pool self-help - Azure Synapse Analytics
Your query might fail with the error message Websocket connection was closed unexpectedly. This message means that your browser connection to ...
Read more >
node-mssql | Microsoft SQL Server client for Node.js
The following example obtains the global connection pool by running sql.connect() , and then runs the query against the pool. NB: It's important...
Read more >
Structured Streaming + Kafka Integration Guide (Kafka broker ...
Creating a Kafka Source for Streaming Queries. Scala; Java; Python ... However, do this with extreme caution as it can cause unexpected behavior....
Read more >
Custom Serialization | Elasticsearch.Net and NEST
For the latest information, see the current release documentation. ... stream, CancellationToken cancellationToken = default(CancellationToken)) => throw ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found