-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Logging before process.exit does not work #1149
Comments
+1 |
1 similar comment
+1 |
This is the most mysterious bug I have came across in ages. |
I did some more tests with code: setTimeout(function() {
throw new Error('Something went wrong!');
}, 1000);
process.on('uncaughtException', function(err) {
console.error( // console.log
'Process uncaughtException:', err.message, '\n',
'Stack:', err.stack
);
process.exit(1);
}); If I use |
Try this: setTimeout(function() {
throw new Error('Something went wrong!');
}, 1000);
process.on('uncaughtException', function(err) {
console.error('Process uncaughtException:', err.stack) //stack does contain message FYI
process.nextTick(function() { process.exit(1) }) // delaying it with a timeout should also work
}); |
It's working, but some new examples :) console.log('You will see only this log message');
process.nextTick(function() {
console.log('You will not see this log message');
console.error('You will see this error message');
process.exit(1);
}); out.log: err.log: console.error('You will see only this error message');
process.nextTick(function() {
console.log('You will see this log message');
console.error('You will not see this error message');
process.exit(1);
}); out.log: err.log: So in case of |
Those are normal behaviors. By calling I haven't understand your second example, |
nodejs/node#1771 related |
Fix this problem with a little hack, this works good:
|
‘Cause |
No idea if it's still useful to comment; but I fixed it by simply doing Just throwing it out there for those who couldn't find an answer, because I know I searched a long while and then half stumbled upon an answer here, but it still didn't properly work with just that. |
OS - Ubuntu 14.04.1 LTS
Node.js - 0.12.0
pm2 - 0.12.9
Sample code:
Run code in cluster mode (1 instance).
process.exit
:There are no my "uncaughtException" messages.
process.exit
:All is good 👍
The text was updated successfully, but these errors were encountered: