Skip to content

Instantly share code, notes, and snippets.

@js-choi
Last active February 10, 2020 14:51
Show Gist options
  • Save js-choi/2024064faeeaafb79e24c6cdec347e22 to your computer and use it in GitHub Desktop.
Save js-choi/2024064faeeaafb79e24c6cdec347e22 to your computer and use it in GitHub Desktop.
Node-Postgres client.end + pool.end hanging
const pg = require('pg');
async function f (callback) {
const pool = new pg.Pool;
const connection = await pool.connect();
await callback(connection);
await connection.end();
await pool.end(); // Commenting this line will prevent the hang.
}
(async () => {
await f(async connection => {
console.log('X');
});
console.log('Y'); // Never runs unless line 8 is commented.
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment