Skip to content

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

Open
@m-ronchi

Description

@m-ronchi

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;
// ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions