Skip to content

pg-cursor usage leads to memory leak #3497

Open
@viladimiru

Description

@viladimiru

If you will execute any read query, you can see in node inspector that GC ignores query result and doesn't cleanup it

const client = new PostgreSqlClient({...credentials, query_timeout: 15 * 60_000});
const cursor = client.query(
    new Cursor(query),
    unhandledErrorCallback,
);
await new Promise((resolve, reject) => {
  cursor.read(100000, (error, _, result) => {
      if (error) {
          reject(error);
      } else {
          resolve(result);
      }
  })
})

This happens because of the callback with timeout cleanup:
https://github.com/brianc/node-postgres/blob/master/packages/pg/lib/client.js#L577
query.callback will not be called even if you closed cursor and destroyed the client

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions