ioredis
ioredis copied to clipboard
Redis Client Error: Error: All sentinels are unreachable. Retrying from scratch after 50ms. Last error: Connection is closed.
@luin I am getting the below issue. Even though all my sentinels are accessible and are running fine.
Version: "ioredis": "^5.3.2" Node.js v16.15.1.
My test code:
import Redis from 'ioredis';
const createRedisClient = () => {
return new Redis({
sentinels: [
{ host: "localhost", port: 26380 },
{ host: "localhost", port: 26381 },
{ host: "localhost", port: 26382 }
],
name: "mymaster",
password: "password",
sentinelRetryStrategy: (times) => {
// reconnect after
return Math.min(times * 50, 2000);
}
});
}
const connectRedis = () => {
const redisClient = createRedisClient();
// handle events
redisClient.on('connect', () => console.log('<:: Redis Client Connected'));
redisClient.on('error', (err) => console.error('<:: Redis Client Error: ', err));
return redisClient;
}
connectRedis();
Error:-
}
<:: Redis Client Error: Error: connect ETIMEDOUT
at Socket.<anonymous> (/Users/raman/Desktop/docker_k8/redissentinal/test/node_modules/ioredis/built/Redis.js:170:41)
at Object.onceWrapper (node:events:641:28)
at Socket.emit (node:events:527:28)
at Socket._onTimeout (node:net:516:8)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect'
}
<:: Redis Client Error: Error: connect ETIMEDOUT
at Socket.<anonymous> (/Users/raman/Desktop/docker_k8/redissentinal/test/node_modules/ioredis/built/Redis.js:170:41)
at Object.onceWrapper (node:events:641:28)
at Socket.emit (node:events:527:28)
at Socket._onTimeout (node:net:516:8)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect'
}
<:: Redis Client Error: Error: All sentinels are unreachable. Retrying from scratch after 50ms. Last error: Connection is closed.
at connectToNext (/Users/raman/Desktop/docker_k8/redissentinal/test/node_modules/ioredis/built/connectors/SentinelConnector/index.js:64:31)
at connectToNext (/Users/raman/Desktop/docker_k8/redissentinal/test/node_modules/ioredis/built/connectors/SentinelConnector/index.js:117:24)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
All docker containers are up and running fine
sentinel.conf
port 26379
dir /tmp
sentinel resolve-hostnames yes
sentinel monitor mymaster redis-master 6379 $SENTINEL_QUORUM
sentinel auth-pass mymaster $REDIS_PASSWORD
sentinel down-after-milliseconds mymaster $SENTINEL_DOWN_AFTER
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster $SENTINEL_FAILOVER
sentinel deny-scripts-reconfig yes
sentinel-entrypoint.sh
#!/bin/sh
sed -i "s/\$SENTINEL_QUORUM/$SENTINEL_QUORUM/g" /redis/sentinel.conf
sed -i "s/\$REDIS_PASSWORD/$REDIS_PASSWORD/g" /redis/sentinel.conf
sed -i "s/\$SENTINEL_DOWN_AFTER/$SENTINEL_DOWN_AFTER/g" /redis/sentinel.conf
sed -i "s/\$SENTINEL_FAILOVER/$SENTINEL_FAILOVER/g" /redis/sentinel.conf
redis-server /redis/sentinel.conf --sentinel
I am also facing the same issue. Here are the debug logs
`2023-07-13T07:39:16.610Z ioredis:redis status[127.0.0.1:26379]: wait -> connecting
backend:start:dev: 2023-07-13T07:39:16.610Z ioredis:redis queue command[127.0.0.1:26379]: 0 -> sentinel([ 'get-master-addr-by-name', 'redis-queue' ])
backend:start:dev: 2023-07-13T07:39:16.610Z ioredis:redis status[127.0.0.1:26379]: connecting -> connect
backend:start:dev: 2023-07-13T07:39:16.610Z ioredis:redis status[127.0.0.1:26379]: connect -> ready
backend:start:dev: 2023-07-13T07:39:16.611Z ioredis:connection send 1 commands in offline queue
backend:start:dev: 2023-07-13T07:39:16.611Z ioredis:redis write command[127.0.0.1:26379]: 0 -> sentinel([ 'get-master-addr-by-name', 'redis-queue' ])
backend:start:dev: 2023-07-13T07:39:16.615Z ioredis:redis write command[127.0.0.1:26379]: 0 -> sentinel([ 'sentinels', 'redis-queue' ])
backend:start:dev: 2023-07-13T07:39:16.617Z ioredis:SentinelConnector Updated internal sentinels: [{"host":"127.0.0.1","port":26379}] @1
backend:start:dev: 2023-07-13T07:39:16.617Z ioredis:SentinelConnector resolved: 192.168.80.2:6379 from sentinel 127.0.0.1:26379
backend:start:dev: 2023-07-13T07:39:16.618Z ioredis:redis status[127.0.0.1:26379]: ready -> close
backend:start:dev: 2023-07-13T07:39:16.618Z ioredis:connection skip reconnecting since the connection is manually closed.
backend:start:dev: 2023-07-13T07:39:16.618Z ioredis:redis status[127.0.0.1:26379]: close -> end
backend:start:dev: 2023-07-13T07:39:26.617Z ioredis:connection error: Error: connect ETIMEDOUT
backend:start:dev: at Socket.
backend:start:dev: at Object.onceWrapper (node:events:627:28)
backend:start:dev: at Socket.emit (node:events:513:28)
backend:start:dev: at Socket._onTimeout (node:net:565:8)
backend:start:dev: at listOnTimeout (node:internal/timers:564:17)
backend:start:dev: at processTimers (node:internal/timers:507:7) {
backend:start:dev: errorno: 'ETIMEDOUT',
backend:start:dev: code: 'ETIMEDOUT',
backend:start:dev: syscall: 'connect'
backend:start:dev: }
backend:start:dev: redis connection error!: Error: connect ETIMEDOUT
backend:start:dev: at Socket.
node_modules/ioredis/built/Redis.js:170:41)
backend:start:dev: at Object.onceWrapper (node:events:627:28)
backend:start:dev: at Socket.emit (node:events:513:28)
backend:start:dev: at Socket._onTimeout (node:net:565:8)
backend:start:dev: at listOnTimeout (node:internal/timers:564:17)
backend:start:dev: at processTimers (node:internal/timers:507:7) {
backend:start:dev: errorno: 'ETIMEDOUT',
backend:start:dev: code: 'ETIMEDOUT',
backend:start:dev: syscall: 'connect'
backend:start:dev: }`
Duplicate of https://github.com/redis/ioredis/issues/1390.