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.

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

See original GitHub issue

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. https://github.com/brianc/node-postgres/issues/2329
  2. https://github.com/brianc/node-postgres/issues/2341

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:12
  • Comments:8

github_iconTop GitHub Comments

3reactions
alfreemacommented, Nov 17, 2021

I was having this issue when using jest to do some integration testing. That lead down a rabbit-hole that solved a bunch of problems including the ability to get pool.end() working properly.

By treating “new Pool()” as a promise, it cleaned my whole mess up:

async function createPool () {
  return await new Pool({ connectionString })
}

and all of the issues with closing clients, pools, etc completely went away just by awaiting “new Pool(…)”. Maybe new Pool needs a Process.nextTick( … ) somewhere? I’m clueless, but hopefully this is a clue to help the brainiacs figure out the underlying problem.

2reactions
snowbldrcommented, Mar 24, 2022

@alfreema I had this same issue. I tried adding await to the new Pool call, and can confirm it did fix it for me. Thanks a bunch for the work around 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is node-postgres (pg) hanging when I call client.connect()?
We are using pg (node-postgres) for our database calls. I upgraded pg to version 7.18.2. Our initialization code looks like this: constructor() ......
Read more >
Changelog - Cypress Documentation
Fixed an issue with Angular Component Testing where urls within SASS/SCSS files were not being correctly resolved which could result in incomplete styling....
Read more >
Considerations in adopting RHEL 8 Red Hat Enterprise Linux 8
Legacy YUM v3 plug-ins are incompatible with the new version of YUM v4. Selected yum plug-ins and utilities have been ported to the...
Read more >
Problem Solving and Troubleshooting in AIX 5L - IBM Redbooks
Before using this information and the product it supports, ... IBM ^ pSeries and RS/6000 system running AIX 5L Version 5.1. It is...
Read more >
Xpress Release Notes - FICO
03). Xpress Solver Interfaces 41.01.01 (Python, MathLab, .NET, and Java). All fixes from Xpress 8.14.3 (Interfaces ...
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