-
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
why i use process.on to catch all uncaughtException, pm2 will restart processes the same #721
Comments
Format please... Bad practice to keep the process alive when you're catching an exception! It's a normal behavior that's all. |
why it is a bad practice to keep the process alive when you're catching an exception. If pm2 restart a process for many times , server handle of customer's requestes will reduces. |
@soyuka, you are correct, this is a bad practice. Although, you got to give people freedom. I believe @newjueqi is saying that sometimes a (micro)service should not be restarted on an unhandled exception. For example when your (micro)service is a simple static file provider you don't want to crash/restart it when a file got missing suddenly, or a file system got inaccessible, or etc. |
Use the default mode, fork_mode instead |
@Unitech That's acceptable. Thanks. |
my script like this:
db.find({
"table":"GameScore",
},function(err,data){
respons11nd(data);
});
In callback function, respons11nd is undefined functions .
If run "node cloud.js", and we use follow code, it can catch the error and this process does not restart:
process.on('uncaughtException', function (err) {
logger.error(err);
});
But if i run "pm2 cloud.js -i max", it will restart the process(I already use process.on to try catch)。Can you tell me why?
And can you tell me pm2 how to judge a process need to restart?
In pro env, I found that after run a long time, it have no processes in "pm2 list" . What's worse, pm2 process is killed. Can you tell me why? is it need to get a better computer for pro env?
my pro env:
nodejs: 0.11.8, pm2: 0.6.13
The text was updated successfully, but these errors were encountered: