Reconnect strategy not being used and ready event fired without being ready.
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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