-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
Description
If the connection to the redis server can't be established, a call to client.disconnect()
won't stop the client from trying to reconnect.
Steps to reproduce
- run the test script below, make sure there is nothing listening on port
65535
so the connection attempt errors withECONNREFUSED
- send
SIGTERM
orSIGINT
to the process (eg. Ctrl + C)
Expected Result
Client stops trying to reconnect and process ends.
2022-02-26T14:24:09.754Z client error connect ECONNREFUSED 127.0.0.1:65535
reconnecting
2022-02-26T14:24:09.909Z client error connect ECONNREFUSED 127.0.0.1:65535
^C
connect error connect ECONNREFUSED 127.0.0.1:65535
command error The client is closed
Actual Result
The client keeps reconnecting, the process keeps running until a second SIGTERM
or SIGINT
is sent (script only listens once to the event)
2022-02-26T14:24:09.754Z client error connect ECONNREFUSED 127.0.0.1:65535
reconnecting
2022-02-26T14:24:09.909Z client error connect ECONNREFUSED 127.0.0.1:65535
^C
disconnect error The client is closed
reconnecting
2022-02-26T14:24:10.113Z client error connect ECONNREFUSED 127.0.0.1:65535
reconnecting
2022-02-26T14:24:10.365Z client error connect ECONNREFUSED 127.0.0.1:65535
reconnecting
^C
Environment:
- Node.js Version: 16.13
- Redis Server Version: 6.2.6
- Node Redis Version: 4.0.4
- Platform: Ubuntu 20.04.4
const { createClient } = require('redis');
let client;
const onError = (err) => {
console.log(new Date(), 'onError', err.message);
}
const onReconnecting = () => {
console.log(new Date(), 'onReconnecting');
}
const handleSignal = async () => {
if (client) try {
await client.disconnect();
} catch (err) {
console.log('disconnect error', err.message);
}
}
(async () => {
process.once('SIGINT', handleSignal);
process.once('SIGTERM', handleSignal);
client = createClient({
socket: {
port: 65535
}
});
client.on('connect', () => console.log('connect'));
client.on('error', err => console.log(new Date(), 'client error', err.message));
client.on('reconnecting', () => console.log('reconnecting'));
try {
await client.connect();
} catch(err) {
console.log('connect error', err.message);
}
try {
await client.incr('mykey');
console.log(await client.get('mykey'));
} catch(err) {
console.log('command error', err.message);
}
})();
rudimadima, dami-i, kevo1ution and spock123