-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
feature request - callbacks in exit handlers - to block even if async code is used #9090
Comments
If there is an unhandled exception, you can register a listener for that which will prevent node from exiting by default: process.on('uncaughtException', function(err) {
console.log('Uncaught exception: ' + err.stack);
// Call shutdown hooks and then exit manually
}); |
that might solve the problem, not sure why it didn't occur to me, let me think about it for a bit |
That's a terrible idea in general. If you have an unexpected exception then by definition your program is in an undefined state. The documentation for the uncaughtException event is very clear that trying to continue, or simply staving off program exit, is a recipe for unpredictable behavior. |
It may be more useful to check to see when the process dies and do external cleanup from another application. |
@bnoordhuis this is for a test framework/library. Errors thrown from test cases may reach the uncaughtException handler. Testing inverts the software development process a bit, because thrown errors are more expected. So in this case, the user/dev will have shutdown hooks that should always run, even if an uncaughtException occurs. Upon an uncaughtException, the test process(es) will exit with a value greater than zero no matter what, that's all that matters in this case. Seen? My current belief is that it would be simply convenient to have the functionality I am looking for, but that uncaughtException handlers will solve the problem, just less conveniently. You can close this if you want :) |
You don't need an uncaughtException listener in order to exit with a non-zero status code, node does that by default. I'll go ahead and close the issue. |
Upon an uncaughtException, the test process(es) will exit with a value You don't need an uncaughtException listener in order to exit with a ....yes but I need the uncaughtException handler to do asynchronous
|
furthermore, I define special exit codes depending on the nature of the
|
I'm on the latest version of Node (6.7)
I have been using Node for awhile and one thing that seems to be a missing feature is shutdown hooks that are "blocking", even if they feature async code. To "block" in this case would require callbacks. A simple use-case is a child_process that needs to use
process.send()
(with a request/reply) pattern with a parent process. process.send() is async, and so we can't be guaranteed the parent process will receive the message before the parent may exit.for example what we have now is this ('beforeExit' might be deprecated or gone by now):
what I am looking for is this type of functionality:
does this functionality exist? The temporary solution is to simply put blocking code in these handlers, but that's not always idea. Hope this makes sense :) I believe it's possible to do this just wondering if it is a sensible request.
The use case is I have programs which need to run shutdown hooks even if there is a fatal exception in the code, these shutdown hooks have asynchronous code by nature (process.send, for one). So it's a feature that I really need.
The text was updated successfully, but these errors were encountered: