brianc / node-postgres

PostgreSQL client for node.js.
https://node-postgres.com
MIT License
12.29k stars 1.23k forks source link

pool.end() not working #3113

Open ashercsulb opened 10 months ago

ashercsulb commented 10 months ago

I ran the sample code you provided and the pool.end() does not seem to work. Code at: https://node-postgres.com/features/pooling

Code console.log("start async query"); const result = await pool.query("SELECT NOW()"); console.log("async query finished, now is: ", result.rows[0].now);

console.log("starting callback query"); pool.query('SELECT NOW()', (err, res) => { console.log("callback query finished, res is: ", res.rows[0].now); });

console.log("calling end"); await pool.end(); console.log("pool has drained");

Output Note: Missing the "callback query finished..." text. start async query async query finished, now is: 2023-12-21T01:54:14.233Z starting callback query calling end pool has drained

Should be as follows: start async query async query finished, now is: 2023-12-21T01:54:14.233Z starting callback query calling end callback query finished.... -- Missing pool has drained

When I comment out the following: await pool.end(); I get the expected behavior ("callback query finished..." is printed at the end).

Output start async query async query finished, now is: 2023-12-21T01:55:50.634Z starting callback query calling end pool has drained callback query finished, res is: 2023-12-21T01:55:50.666Z

Md-Anamul-Haque commented 6 months ago

There is no need to end the pool. Because it is connect and end itself.If you want to end then use client.