You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
fix(pool): chain promise handlers to prevent unhandled rejections (#3035)
This commit is contained in:
@@ -8,4 +8,35 @@ describe('RedisClientPool', () => {
|
|||||||
'PONG'
|
'PONG'
|
||||||
);
|
);
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, 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);
|
const result = fn(node.value);
|
||||||
if (result instanceof Promise) {
|
if (result instanceof Promise) {
|
||||||
result.then(resolve, reject);
|
result
|
||||||
result.finally(() => this.#returnClient(node))
|
.then(resolve, reject)
|
||||||
|
.finally(() => this.#returnClient(node))
|
||||||
} else {
|
} else {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
this.#returnClient(node);
|
this.#returnClient(node);
|
||||||
|
Reference in New Issue
Block a user