1
0
mirror of https://github.com/redis/node-redis.git synced 2025-07-31 05:44:24 +03:00

fix(pool): chain promise handlers to prevent unhandled rejections (#3035)

This commit is contained in:
Pavel Pashov
2025-07-25 16:39:32 +03:00
committed by GitHub
parent e96db0d13c
commit ff8319d2d7
2 changed files with 34 additions and 2 deletions

View File

@ -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
);
});

View File

@ -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);