You've already forked node-redis
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:
@ -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
|
||||
);
|
||||
});
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user