From ff8319d2d7fe7afb6ae1eb129ff5526370aef4af Mon Sep 17 00:00:00 2001 From: Pavel Pashov <60297174+PavelPashov@users.noreply.github.com> Date: Fri, 25 Jul 2025 16:39:32 +0300 Subject: [PATCH] fix(pool): chain promise handlers to prevent unhandled rejections (#3035) --- packages/client/lib/client/pool.spec.ts | 31 +++++++++++++++++++++++++ packages/client/lib/client/pool.ts | 5 ++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/client/lib/client/pool.spec.ts b/packages/client/lib/client/pool.spec.ts index 8fc7a258df..f292dc171c 100644 --- a/packages/client/lib/client/pool.spec.ts +++ b/packages/client/lib/client/pool.spec.ts @@ -8,4 +8,35 @@ describe('RedisClientPool', () => { 'PONG' ); }, GLOBAL.SERVERS.OPEN); + + testUtils.testWithClientPool( + 'proper error propagation in sequential operations', + async (pool) => { + let hasUnhandledRejection = false; + + process.once('unhandledRejection', () => { + hasUnhandledRejection = true; + }); + + const groupName = 'test-group'; + const streamName = 'test-stream'; + + // First attempt - should succeed + await pool.xGroupCreate(streamName, groupName, '0', { + MKSTREAM: true, + }); + + // Subsequent attempts - should all throw BUSYGROUP errors and be handled properly + for (let i = 0; i < 3; i++) { + await assert.rejects( + pool.xGroupCreate(streamName, groupName, '0', { + MKSTREAM: true, + }) + ); + } + + assert.equal(hasUnhandledRejection, false); + }, + GLOBAL.SERVERS.OPEN + ); }); diff --git a/packages/client/lib/client/pool.ts b/packages/client/lib/client/pool.ts index 6f633c9caa..b53bb2c7e6 100644 --- a/packages/client/lib/client/pool.ts +++ b/packages/client/lib/client/pool.ts @@ -438,8 +438,9 @@ export class RedisClientPool< ) { const result = fn(node.value); if (result instanceof Promise) { - result.then(resolve, reject); - result.finally(() => this.#returnClient(node)) + result + .then(resolve, reject) + .finally(() => this.#returnClient(node)) } else { resolve(result); this.#returnClient(node);