redis / redis/node-redis

Reconnect strategy not being used and ready event fired without being ready.

Open
#2,120 12 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
TypeScript
Stars
17.6k
Forks
2k
Avg merge
2d 3h
Merged PRs (30d)
40

Description

I've recently upgraded to node redis 4.1.0 and I'm having issues with reconnectStrategy and connection handling in general.

Logs from reconnectstrategy are never printed.
When I start with redis server down. I still get the ready event triggered. A bit later I get an error event and it immediately "connects" (triggering ready again); And this just continues; The 5 second reconnect timer is not used.

When redis is online when I start the application and I later turn it off: it seems to go even faster. It does not wait long between the ready event and an error.

I'm initializing redis like so:

const options: RedisClientOptions<RedisModules, RedisFunctions, S> = {
    username: this.username,
    password: this.password,
    socket: {
        host: this.host,
        port: this.port,
        reconnectStrategy: (attempts) => {
            console.log(`Redis reconnecting attempt ${attempts}`);
            this.connected = false;
            if (attempts == 1) {
                console.log(`${this.constructor.name} failed to connect to ${this.host}:${this.port}. Reconnecting...`);
            }
            return 5000;
        },
    },
    scripts: scripts,
};
const redisClient = createClient(options);
redisClient.on('ready', () => {
    console.log(`${this.constructor.name} connected to ${this.host}:${this.port}`);
});
redisClient.on('error', (err) => {
    console.log('error');
    return;
});
redisClient.on('reconnecting', () => {
    return;
});
redisClient.on('end', () => {
    return;
});
redisClient.on('connect', () => {
    return;
});

redisClient.connect();

Environment:

  • Node.js Version: v14.16.0
  • Node Redis Version: 4.1.0
  • Platform: Mac OS 12.3.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the report with the shown TypeScript createClient options and the socket reconnectStrategy, then trace the connect, ready, error, and reconnecting event flow. The issue names no repository files or tests; done means the configured five-second strategy is honored and ready is not emitted before the client is actually ready.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, redis, typescript
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.