From 303ffc2375a791404313d6643b302a6c7df01f85 Mon Sep 17 00:00:00 2001 From: Krish Modi Date: Sun, 30 Nov 2025 23:40:09 +0530 Subject: [PATCH 1/3] Fix PoolConnection.end() callback and promise resolution --- lib/base/pool_connection.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/base/pool_connection.js b/lib/base/pool_connection.js index b74c168938..9c39536207 100644 --- a/lib/base/pool_connection.js +++ b/lib/base/pool_connection.js @@ -29,23 +29,26 @@ class BasePoolConnection extends BaseConnection { this._pool.releaseConnection(this); } - end() { + end(callback) { if (this.config.gracefulEnd) { this._removeFromPool(); - super.end(); + super.end(callback); return; } const err = new Error( 'Calling conn.end() to release a pooled connection is ' + - 'deprecated. In next version calling conn.end() will be ' + - 'restored to default conn.end() behavior. Use ' + - 'conn.release() instead.' + 'deprecated. In next version calling conn.end() will be ' + + 'restored to default conn.end() behavior. Use ' + + 'conn.release() instead.' ); this.emit('warn', err); console.warn(err.message); this.release(); + if (callback) { + callback(); + } } destroy() { From 58dee538c582d8a2d45e909ea3da8221f4908bb5 Mon Sep 17 00:00:00 2001 From: Krish Modi Date: Mon, 1 Dec 2025 00:39:05 +0530 Subject: [PATCH 2/3] Revise deprecation warning for conn.end() method Updated deprecation warning message for conn.end() usage. --- lib/base/pool_connection.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/base/pool_connection.js b/lib/base/pool_connection.js index 9c39536207..95f61c9aa0 100644 --- a/lib/base/pool_connection.js +++ b/lib/base/pool_connection.js @@ -39,9 +39,9 @@ class BasePoolConnection extends BaseConnection { const err = new Error( 'Calling conn.end() to release a pooled connection is ' + - 'deprecated. In next version calling conn.end() will be ' + - 'restored to default conn.end() behavior. Use ' + - 'conn.release() instead.' + 'deprecated. In next version calling conn.end() will be ' + + 'restored to default conn.end() behavior. Use ' + + 'conn.release() instead.' ); this.emit('warn', err); console.warn(err.message); From 498574b91e54da254b96e49fb2fc2fc958dbccdf Mon Sep 17 00:00:00 2001 From: Krish Modi Date: Mon, 1 Dec 2025 00:52:39 +0530 Subject: [PATCH 3/3] Refactor connection handling in graceful end tests --- ...test-end-with-graceful-end-config.test.cjs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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'); });