Description
Given this snippet:
import { createClientPool } from '@redis/client';
const pool = createClientPool(
{ host: 'localhost', tls: false, port: 6379 },//
{
minimum: 0,
maximum: 3,
})
process.on('uncaughtException', (err) => {
console.debug({ uncaught: err.message });
});
await pool.connect();
const command1 = pool.execute(async function task (client) {
console.debug('Task 1 started')
await new Promise((resolve) => setTimeout(resolve, 2000));
console.debug('Task 1 ended')
});
const command2 = pool.execute(async function task (client) {
console.debug('Task 2 started')
await new Promise((resolve) => setTimeout(resolve, 2000));
console.debug('Task 2 ended')
});
await pool.close();
console.debug('Closed')
await Promise.all([command1, command2]);
console.debug('Command done')
setTimeout(() => {
console.debug({
totalClients: pool.totalClients,
idleClients: pool.idleClients,
clientsInUse: pool.clientsInUse,
isOpen: pool.isOpen,
})
}, 5000);
For what I saw there are a couple of issue:
- The
cleanup should check if the pool is open (this._self.#isOpen) before calling destroy on the connections. This would solve the uncaught error
- When the task is not completed, the
client can be in-use. So the close should take into account the pending promise instead
- The
this._self.#isOpen is not set to false when the close() completes
Node.js Version
node@22.14
Redis Server Version
redis_version:8.2.3
Node Redis Version
@redis/client@5.10.0
Platform
macOS
Logs
The output is:
Closed
Task 1 started
Task 2 started
Task 1 ended
Task 2 ended
Command done
{ uncaught: 'The client is closed' }
{ totalClients: 1, idleClients: 1, clientsInUse: 0, isOpen: true }