From 6d223d53166370caf7f1be1069265dfdaac9c783 Mon Sep 17 00:00:00 2001 From: GiHoon1123 Date: Wed, 19 Aug 2026 12:48:09 +0900 Subject: [PATCH 1/2] fix(promise): forward pool error events --- lib/promise/pool.js | 8 +++++++- promise.d.ts | 1 + .../test-promise-wrappers.test.mts | 12 +++++++++++- test/tsc-build/promise/createPool/on.test.ts | 14 ++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test/tsc-build/promise/createPool/on.test.ts diff --git a/lib/promise/pool.js b/lib/promise/pool.js index 7d8c13c6d0..7526e58fdd 100644 --- a/lib/promise/pool.js +++ b/lib/promise/pool.js @@ -15,7 +15,13 @@ class PromisePool extends EventEmitter { super(); this.pool = pool; this.Promise = thePromise || Promise; - inheritEvents(pool, this, ['acquire', 'connection', 'enqueue', 'release']); + inheritEvents(pool, this, [ + 'acquire', + 'connection', + 'enqueue', + 'error', + 'release', + ]); } getConnection() { diff --git a/promise.d.ts b/promise.d.ts index 93c6641bac..bb724bec5f 100644 --- a/promise.d.ts +++ b/promise.d.ts @@ -94,6 +94,7 @@ export interface Pool extends Connection { releaseConnection(connection: PoolConnection): void; + on(event: 'error', listener: (err: NodeJS.ErrnoException) => any): this; on(event: 'connection', listener: (connection: PoolConnection) => any): this; on(event: 'acquire', listener: (connection: PoolConnection) => any): this; on(event: 'release', listener: (connection: PoolConnection) => any): this; diff --git a/test/integration/promise-wrappers/test-promise-wrappers.test.mts b/test/integration/promise-wrappers/test-promise-wrappers.test.mts index f9ec2d2b20..4cb260b12b 100644 --- a/test/integration/promise-wrappers/test-promise-wrappers.test.mts +++ b/test/integration/promise-wrappers/test-promise-wrappers.test.mts @@ -259,6 +259,7 @@ await describe('testEventsPool', async () => { acquire: 0, connection: 0, enqueue: 0, + error: 0, release: 0, }; for (const eventName in expectedListeners) { @@ -291,6 +292,14 @@ await describe('testEventsPool', async () => { ++events; }.bind(pool) ) + .once( + 'error', + function (err: Error) { + strict.equal(this, pool); + strict.equal(err.message, 'pool error'); + ++events; + }.bind(pool) + ) .once( 'release', function () { @@ -302,9 +311,10 @@ await describe('testEventsPool', async () => { pool.pool.emit('acquire'); pool.pool.emit('connection'); pool.pool.emit('enqueue'); + pool.pool.emit('error', new Error('pool error')); pool.pool.emit('release'); - strict.equal(events, 4, 'wrong number of pool connection events'); + strict.equal(events, 5, 'wrong number of pool connection events'); for (const eventName in expectedListeners) { strict.equal( diff --git a/test/tsc-build/promise/createPool/on.test.ts b/test/tsc-build/promise/createPool/on.test.ts new file mode 100644 index 0000000000..330bbfc3d3 --- /dev/null +++ b/test/tsc-build/promise/createPool/on.test.ts @@ -0,0 +1,14 @@ +import { mysqlp as mysql } from '../../index.test.js'; +import { access } from '../baseConnection.test.js'; + +const pool = mysql.createPool(access); + +pool.on('error', (err) => { + const code: string | undefined = err.code; + code; + err.message; +}); + +pool.on('connection', (connection) => { + connection.threadId; +}); From c7b7e4f2a21d4f958ff1ffae210940507ca42237 Mon Sep 17 00:00:00 2001 From: Gihoon1123 Date: Sat, 19 Sep 2026 11:46:36 +0900 Subject: [PATCH 2/2] fix(promise): drop the error event forwarding Pool never emits 'error' itself - PoolConnection swallows connection errors internally (once('error', () => this._removeFromPool())), so the forwarding added here had nothing to forward. Scoping this back to what #3749 actually needs. --- lib/promise/pool.js | 8 +------- promise.d.ts | 1 - .../test-promise-wrappers.test.mts | 12 +----------- test/tsc-build/promise/createPool/on.test.ts | 14 -------------- 4 files changed, 2 insertions(+), 33 deletions(-) delete mode 100644 test/tsc-build/promise/createPool/on.test.ts diff --git a/lib/promise/pool.js b/lib/promise/pool.js index c902dc1194..13fdee3eca 100644 --- a/lib/promise/pool.js +++ b/lib/promise/pool.js @@ -15,13 +15,7 @@ class PromisePool extends EventEmitter { super(); this.pool = pool; this.Promise = thePromise || Promise; - inheritEvents(pool, this, [ - 'acquire', - 'connection', - 'enqueue', - 'error', - 'release', - ]); + inheritEvents(pool, this, ['acquire', 'connection', 'enqueue', 'release']); } getConnection() { diff --git a/promise.d.ts b/promise.d.ts index bb724bec5f..93c6641bac 100644 --- a/promise.d.ts +++ b/promise.d.ts @@ -94,7 +94,6 @@ export interface Pool extends Connection { releaseConnection(connection: PoolConnection): void; - on(event: 'error', listener: (err: NodeJS.ErrnoException) => any): this; on(event: 'connection', listener: (connection: PoolConnection) => any): this; on(event: 'acquire', listener: (connection: PoolConnection) => any): this; on(event: 'release', listener: (connection: PoolConnection) => any): this; diff --git a/test/integration/promise-wrappers/test-promise-wrappers.test.mts b/test/integration/promise-wrappers/test-promise-wrappers.test.mts index 4cb260b12b..f9ec2d2b20 100644 --- a/test/integration/promise-wrappers/test-promise-wrappers.test.mts +++ b/test/integration/promise-wrappers/test-promise-wrappers.test.mts @@ -259,7 +259,6 @@ await describe('testEventsPool', async () => { acquire: 0, connection: 0, enqueue: 0, - error: 0, release: 0, }; for (const eventName in expectedListeners) { @@ -292,14 +291,6 @@ await describe('testEventsPool', async () => { ++events; }.bind(pool) ) - .once( - 'error', - function (err: Error) { - strict.equal(this, pool); - strict.equal(err.message, 'pool error'); - ++events; - }.bind(pool) - ) .once( 'release', function () { @@ -311,10 +302,9 @@ await describe('testEventsPool', async () => { pool.pool.emit('acquire'); pool.pool.emit('connection'); pool.pool.emit('enqueue'); - pool.pool.emit('error', new Error('pool error')); pool.pool.emit('release'); - strict.equal(events, 5, 'wrong number of pool connection events'); + strict.equal(events, 4, 'wrong number of pool connection events'); for (const eventName in expectedListeners) { strict.equal( diff --git a/test/tsc-build/promise/createPool/on.test.ts b/test/tsc-build/promise/createPool/on.test.ts deleted file mode 100644 index 330bbfc3d3..0000000000 --- a/test/tsc-build/promise/createPool/on.test.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { mysqlp as mysql } from '../../index.test.js'; -import { access } from '../baseConnection.test.js'; - -const pool = mysql.createPool(access); - -pool.on('error', (err) => { - const code: string | undefined = err.code; - code; - err.message; -}); - -pool.on('connection', (connection) => { - connection.threadId; -});