diff --git a/lib/base/pool_connection.js b/lib/base/pool_connection.js index b74c168938..95f61c9aa0 100644 --- a/lib/base/pool_connection.js +++ b/lib/base/pool_connection.js @@ -29,10 +29,10 @@ class BasePoolConnection extends BaseConnection { this._pool.releaseConnection(this); } - end() { + end(callback) { if (this.config.gracefulEnd) { this._removeFromPool(); - super.end(); + super.end(callback); return; } @@ -46,6 +46,9 @@ class BasePoolConnection extends BaseConnection { this.emit('warn', err); console.warn(err.message); this.release(); + if (callback) { + callback(); + } } destroy() { diff --git a/test/integration/graceful-end/test-end-with-graceful-end-config.test.cjs b/test/integration/graceful-end/test-end-with-graceful-end-config.test.cjs index 2fa7bbe048..c3a9dec72a 100644 --- a/test/integration/graceful-end/test-end-with-graceful-end-config.test.cjs +++ b/test/integration/graceful-end/test-end-with-graceful-end-config.test.cjs @@ -15,7 +15,10 @@ const { assert } = require('poku'); const pool = new createPool({ gracefulEnd: true }); let warningEmitted = false; -pool.getConnection((_err1, connection) => { +pool.getConnection((err, connection) => { + if (err) { + throw err; + } connection.on('warn', () => { warningEmitted = true; }); @@ -24,6 +27,20 @@ pool.getConnection((_err1, connection) => { pool.end(); }); +const pool2 = new createPool({ gracefulEnd: true }); +pool2.getConnection((err, connection) => { + if (err) { + throw err; + } + connection.on('warn', () => { + warningEmitted = true; + }); + + connection.end(() => { + pool2.end(); + }); +}); + process.on('exit', () => { assert(!warningEmitted, 'Warning should not be emitted'); });