-
Notifications
You must be signed in to change notification settings - Fork 15
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
Cannot bind uncaughtException & unhandledRejection together #5
Comments
Sorry for the late response!
Yes, one might want to bind different handlers. Should make a generic exit handler though.. Any suggestions for names etc.?
Interesting idea, I'll have to give this further thought, but possibly. |
on the exit function, that would be a good idea, as then there's a safe way to exit the process. |
Currently figuring out all the implications of this. I'll try to carve out some more OSS time next weekend and get this in. Small change but node's process lifecycle is quite unfriendly to customisation, in part due to OS differences. |
@Tapppi working with AsyncExitHook more essentially what I think it needs to do is simply
|
@Tapppi any movement here? |
Just saying, I ran across this again today |
Workaround for now. dont use either function and do this instead. import asyncExitHook from 'async-exit-hook';
let stopped = false;
/**
* closes thingy before exiting
* @param {function} cb callback for async exit hook
*/
function shutdown(cb = () => {}) {
if (!stopped) {
stopped = true;
Logger.info('thingy is shutting down...');
thingy1.stop((success) => {
thingy2.shutdown().finally(() => cb());
});
}
}
asyncExitHook((cb) => {
Logger.info('thingy is exiting');
shutdown(cb);
});
asyncExitHook.hookEvent('uncaughtException', 1, (err) => {
Logger.fatal('thingy is shutting down due to UncaughtException...');
return false;
});
asyncExitHook.hookEvent('unhandledRejection', 2, (err) => {
Logger.fatal('thingy is shutting down due to unhandledRejectionHandler...');
return false;
}); |
@Tapppi: this problem needs to write in the documentation. Or need to fix it. |
please fix this, i lost a few hours debugging |
There are two problems with the current implementation: 1. Only the first hooked event is registered.Both registration functions check for the single Line 151 in 80e692c
Line 160 in 80e692c
2. All error hook handlers will be called, even if they weren't registered on that event (from 1).Both errors trigger all Line 69 in 80e692c
SolutionBoth can be fixed by using separate arrays - eg Line 67 in 80e692c
|
Hello,
it looks like you can bind to both. Is there any particoular reason?
Also, would you expose the exit function so that one can eventually calll it manually?
The text was updated successfully, but these errors were encountered: