Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in reconnecting event listener silently prevents reconnection #2234

Closed
ryanmeador opened this issue Aug 15, 2022 · 0 comments · Fixed by #2226
Closed

error in reconnecting event listener silently prevents reconnection #2234

ryanmeador opened this issue Aug 15, 2022 · 0 comments · Fixed by #2226
Labels

Comments

@ryanmeador
Copy link

As I commented on #2032, I discovered that if the reconnecting event listener throws an error, it will silently prevent reconnection from happening. No error message will be logged, and there is no indication anything has gone wrong except that it just doesn't ever attempt to reconnect. I think it would be helpful if an error message was logged in this situation and the reconnection was able to proceed.

This is easiest to reproduce using Heroku's Redis server, which by default closes all connections after 5 minutes of inactivity.

Environment:

  • Node.js Version: 16.15.1
  • Redis Server Version: 6.2.3 (Heroku)
  • Node Redis Version: 4.2.0
  • Platform: MacOS 12.5

Reproducer:

import { createClient } from "redis";

export const client = createClient({ url: process.env.REDIS_URL });

client.on('error', err => console.log(`Redis error: ${err}`));
// the below line works fine
//client.on('reconnecting', () => console.log('Redis reconnecting'));
// the below line causes an error, which is swallowed and silently prevents reconnect
client.on('reconnecting', (foo) => console.log('Redis reconnecting' + foo.bar));
client.on('connect', () => console.log('Redis connected'));
client.on('ready', () => console.log('Redis ready'));
client.on('end', () => console.log('Redis connection closed'));

await client.connect();

Output in the broken case:

Redis connected
Redis ready
Redis error: Error: Socket closed unexpectedly

Output in the working case (uncomment the working line and comment the broken line):

Redis connected
Redis ready
Redis error: Error: Socket closed unexpectedly
Redis reconnecting
Redis connected
Redis ready

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant