pnxtech / hydra-express

A module which wraps Hydra and ExpressJS into a library for building distributed applications - such as microservices
MIT License
184 stars 37 forks source link

End main process if redis is unavailable at boot #133

Closed tomascasas closed 2 years ago

tomascasas commented 2 years ago

When Redis is not reachable upon start() execution, it happens before process.on('cleanup', () => {...}) is wired. The result is a stale hydra-express that cannot be collected by the container, thus cannot be restarted.

In this case a Docker HEALTHCHECK or a Kubernetes livenessProbe for the deployment/.../container could help terminating and starting a new deployment.

This splits the try/catch block in 2, the first block will immediately process.exit(1);. The second will trigger process.emit('cleanup') upon an exception and that will be handled by the listener, properly shutdown the service.