-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
ioredis doesn't emit MaxRetriesPerRequestError when Redis error is down!~
ioredis ver: 4.17.3
This is not working in my production APP so I have prepared small test project to check if I am able to repeat the same and indeed I can.
Code:
const Redis = require("ioredis");
function connectToRedis(redisProps) {
const redisDefaultProps = {
host: "127.0.0.1",
port: "6379",
db: 1,
maxRetriesPerRequest: 20,
retryStrategy(times) {
console.warn(`Retrying redis connection: attempt ${times}`);
return Math.min(times * 500, 2000);
},
};
const g_redis = new Redis({ ...redisDefaultProps, ...redisProps });
g_redis.on("connecting", () => {
console.log("Connecting to Redis.");
});
g_redis.on("connect", () => {
console.log("Success! Redis connection established.");
});
g_redis.on("error", (err) => {
if (err.code === "ECONNREFUSED") {
console.warn(`Could not connect to Redis: ${err.message}.`);
} else if (err.name === "MaxRetriesPerRequestError") {
console.error(`Critical Redis error: ${err.message}. Shutting down.`);
process.exit(1);
} else {
console.error(`Redis encountered an error: ${err.message}.`);
}
});
}
connectToRedis();
I have tried to setup different versions of Redis and the problem appears no matter which I use.
I have also tried to setup Redis on different hosts and I get the same error.
Scenario:
- Start Redis server
- Start the app with node index.js
- Connection is established
- Go to Redis server host and shutdown the Redis process with 'kill -9 Redis_PID' or stop the Redis service with 'sudo systemctl stop redis' (CentOS 7.5).
- ioredis detects following and is starting retryStrategy described in above code:
Retrying redis connection: attempt 18
Could not connect to Redis: connect ECONNREFUSED 127.0.0.1:6379.
Bug:
The strategy keeps going. No MaxRetriesPerRequestError is emitted. The app is not stopped.
Could not connect to Redis: connect ECONNREFUSED 127.0.0.1:6379.
Retrying redis connection: attempt 27
Expected behavior:
retryStrategy reaches maxRetriesPerRequest limit and emits MaxRetriesPerRequestError.
skulas, ktamaral, tomislater, niradler, DiegoFleitas and 2 more
Metadata
Metadata
Assignees
Labels
No labels