Retrying Redis connection attempts keeps going to infinite when MaxRetriesPerRequestError is handled
Problem
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: [code block] 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: 1. Start Redis server 2. Start the app with node index.js 3. Connection is established 4. 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). 5. ioredis detects following and is starting retryStrategy described in above code: [code block] Bug: The strategy keeps going. No MaxRetriesPerRequestError is emitted. The app is not stopped. [code block] Expected behavior: retryStrategy reaches maxRetriesPerRequest limit and emits MaxRetriesPerRequestError.
Error Output
Error when Redis error is down!~
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Retrying Redis connection attempts keeps going to infinite when MaxRetriesPerRequestError is handled
@kapalkat Try set the lazyConnect: true, this.redis = new Redis({ db: 0, host: process.env.REDIS_HOST || 'localhost', port: process.env.REDIS_PORT || 6379, lazyConnect: true, }); after remake your test.
Trust Score
4 verifications
- 1
Try set the lazyConnect: true,
Try set the lazyConnect: true,
- 2
this.redis = new Redis({
db: 0, host: process.env.REDIS_HOST || 'localhost', port: process.env.REDIS_PORT || 6379, lazyConnect: true, });
Validation
Resolved in redis/ioredis GitHub issue #1146. Community reactions: 5 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep