FG
🗄️ Databases

Retrying Redis connection attempts keeps going to infinite when MaxRetriesPerRequestError is handled

Freshabout 3 years ago
Mar 14, 20260 views
Confidence Score78%
78%

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

Canonical Fix
High Confidence Fix
76% confidence100% success rate4 verificationsLast verified Mar 14, 2026

Solution: Retrying Redis connection attempts keeps going to infinite when MaxRetriesPerRequestError is handled

Low Risk

@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.

76

Trust Score

4 verifications

100% success
  1. 1

    Try set the lazyConnect: true,

    Try set the lazyConnect: true,

  2. 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

Worked: 4
Partial: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

redisiorediscache