-
Notifications
You must be signed in to change notification settings - Fork 32
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
Connection errors are silent #95
Comments
Good spot! |
Hi, I've encountered the same problem while working with the plugin. Can i try to give it a shot to fix it? |
go for it! |
I was thinking about two possible solutions:
Have you any strong opinion on one approach or another? I could prepare both PRs to see a working examples of the approaches and then decide which would fit better. |
I would go with the second approach. |
I'd reopen this issue. The connection is checked at server startup but when the connection is exited after retry the app will stay in an unhealthy state forever. The plugin needs to listen to the
Sry, I had no bandwidth to check the PR. |
I have to correct myself. In order to allow reconnecting the const maxConnectionRetry = 5;
const retryStrategy = function (times) {
if (times >= maxConnectionRetry) {
return null;
}
const delay = Math.min(Math.pow(2, times) * 50, 2000);
return delay;
}
const redisClient = new Redis(options.url, {
commandTimeout: 2000, // ms
enableReadyCheck: true,
retryStrategy,
});
this.client
.on('reconnecting', (times: number) => {
this.loggingService.log.warn(
`Redis reconnecting in ${times}ms`,
);
})
.on('end', () => {
const err = new Error('Redis max retry');
this.loggingService.log.error(
err,
'redis max connection retries',
);
// (pseudo) will lead to graceful shutdown
gracefulShutdown()
})
.on('error', (err) => {
this.loggingService.log.error(err, 'redis error');
// we swallow errors here to run the reconnection logic
// if the client can't connect the `end` event will fire
})
.on('ready', async () => {
this.loggingService.log.info('Connected with redis');
}); |
Prerequisites
Fastify version
3.18.0
Plugin version
No response
Node.js version
14.x
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
20.04
Description
Fastify-redis rely on ioredis that doesn't exit the process when the connection can't be restored.
We need to register an
error
handler on ioedis and graceful shutdown the application.Steps to Reproduce
Pass an invalid redis url or shutdown the redis instance during connection. No error is thrown but the app is still alive.
Expected Behavior
If the application can't recover itself the instance must exit so that your orchestration software can't mark it as unhealthy and create a new one.
The text was updated successfully, but these errors were encountered: