Skip to content

Redis client stucks in reconnection loop #3108

@sergeyzwezdin

Description

@sergeyzwezdin

Description

import { createClient } from 'redis'

// ...

        this.redisClient = createClient({
            url: 'redis://localhost:6379',
            disableOfflineQueue: true,
            socket: {
                connectTimeout: 1000,
            },
        })
            .on('error', () => {
                console.log('🙉 REDIS ERROR')
            })
            .on('connect', () => {
                console.log('🙃 REDIS CONNECT')
            })
            .on('ready', () => {
                console.log('😎 REDIS READY')
            })
            .on('end', () => {
                console.log('👋 REDIS END')
            })
            .on('close', () => {
                console.log('👊 REDIS CLOSE')
            })
            .on('reconnecting', () => {
                console.log('🫠  REDIS RECONNECTING')
            })
            .on('reconnect', () => {
                console.log('🤗 REDIS RECONNECT')
            })
            .on('invalidate', () => {
                console.log('🫡 REDIS INVALIDATE')
            })

Steps to reproduce:

  1. Start Redis
  2. Run code listed above
  3. Terminal output:
🙃 REDIS CONNECT
😎 REDIS READY
  1. Stop Redis
  2. Terminal output:
🙉 REDIS ERROR
🫠  REDIS RECONNECTING
🙃 REDIS CONNECT
🙉 REDIS ERROR
😎 REDIS READY

Notice last REDIS READY.
Next, once Redis server restarted it could not reconnect.

The bug was introduced starting 5.0.0. Works okay on 4.7.0

Node.js Version

24.7.0

Redis Server Version

7.4.6

Node Redis Version

5.9.0

Platform

macOS

Logs

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions