client.connect() does not throw error on non-existing or closed host:port pair
Description
I was debugging why my pub/sub system does not work and then realised that some ports might be closed. To verify that, I have passed totally random host and port to my connection, and it said CONNECTED!!! Expected behavious is that it should not allow you to "fake-connect" to any host and throw an error on timeout! .on('connect') callback IS called, and does not contain any error... .on('error') callback is not called AT ALL...
const sub = createClient(redisOptions);
sub.on('error', cb);
sub.on('connect', () => {
// this is executed without any error, error is expected
});
await sub.connect();
console.log('CONNECTED'); - Outputs on non-existing host, error is expected
Node.js Version
18.20.2
Redis Server Version
6.0.16
Node Redis Version
4.6.10
Platform
Ubuntu
Logs
No response
I just ran this script:
import { createClient } from 'redis';
await createClient({ host: '127.0.0.1', port: 6379 })
.on('error', err => console.error(err))
.on('connect', () => console.log('connected'))
.connect();
and this is what I'm getting:
Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1602:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 6379
}
by default the client will try to reconnect forever, but you can change that using socket.reconnectStrategy (see https://github.com/redis/node-redis/blob/master/docs/client-configuration.md#reconnect-strategy)
This issue has been automatically marked as stale due to inactivity. It will be closed in 30 days if no further activity occurs. If you believe this issue is still relevant, please add a comment to keep it open.
This issue has been automatically closed due to inactivity. If you believe this issue is still relevant, please reopen it or create a new issue with updated information.