From 107df4fa8186286c80c94185778238f2e97e65db Mon Sep 17 00:00:00 2001 From: Josh Betz Date: Wed, 27 Nov 2024 15:34:41 -0600 Subject: [PATCH] remove forwardPoolErrors instead of needing to explicitly set forwardPoolErrors, always forward errors if there's a listener. We don't want to forward errors unconditionally because it counts as an uncaught error if there is no listener. --- src/hashpool.ts | 2 -- src/pool.ts | 11 +++++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/hashpool.ts b/src/hashpool.ts index ff5acb1..603db55 100644 --- a/src/hashpool.ts +++ b/src/hashpool.ts @@ -47,8 +47,6 @@ export default class HashPool extends EventEmitter { socketTimeout: 100, }, opts ); - this.opts.forwardPoolErrors = true; - // initialize hash pool for ( const node of nodes ) { this.connect( node ); diff --git a/src/pool.ts b/src/pool.ts index 64bc306..c90a942 100644 --- a/src/pool.ts +++ b/src/pool.ts @@ -11,7 +11,6 @@ export type PoolOptions = { idleTimeoutMillis: number; // internal - forwardPoolErrors: boolean; autostart: boolean; fifo: boolean; evictionRunIntervalMillis: number; @@ -25,8 +24,6 @@ export default class Pool extends EventEmitter { super(); this.opts = Object.assign( { - forwardPoolErrors: false, - // Pool options max: 10, min: 2, @@ -46,9 +43,11 @@ export default class Pool extends EventEmitter { this.pool = createPool( { create: async () => { const memcached = new Memcached( port, host, this.opts ); - if ( this.opts.forwardPoolErrors ) { - memcached.on( 'error', ( error: Error ) => this.emit( 'error', error ) ); - } + memcached.on( 'error', ( error: Error ) => { + if ( this.listeners( 'error' ).length ) { + this.emit( 'error', error ); + } + } ); await memcached.ready(); return memcached;