Skip to content

pg version 8.7.1 hangs on await db.end() but before version 8 doesn't #2648

Open
@Animadei

Description

@Animadei

The node-postgres module frequently hangs when the PostgreSQL server restarts abruptly. The node-postgres package was working fine prior to pg version 8.7.1 as required by Node.js version 16. The two positions marked A and B represents when a disconnect from the database could be experienced. The db.end() API hangs on the await in the bad case. Commenting out the await avoids the hang.

let db = null;

try {
  db = new pg.Client({...});
  await db.connect();
  // Position A
  await db.query("<SQL query>");
  // Position B
} finally {
  if (db) {
//    await db.end(); // the await can hang indefinitely
    db.end(); // workaround fix
  }
}

The Client.end() routine has a new implementation. Could someone check the logic to guarantee the Client.end() returned promise always resolves.

The two related issues are:

  1. Connection hang on the server side after ended #2329
  2. Bug in pool.end () never returns when trying to close cleanly #2341

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