Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.

Home Page:https://pm2.keymetrics.io/docs/usage/quick-start/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

why i use process.on to catch all uncaughtException, pm2 will restart processes the same

newjueqi opened this issue · comments

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

Format please...

Bad practice to keep the process alive when you're catching an exception! It's a normal behavior that's all.
Maybe this can interest you.

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.
Please, close the issue.