Skip to content
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

Closed
newjueqi opened this issue Sep 18, 2014 · 5 comments

Comments

@newjueqi
Copy link

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

@soyuka
Copy link
Collaborator

soyuka commented Sep 18, 2014

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.

@soyuka soyuka added the waiting label Sep 19, 2014
@newjueqi
Copy link
Author

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.

@koresar
Copy link

koresar commented Nov 24, 2014

@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.

@Unitech
Copy link
Owner

Unitech commented Nov 26, 2014

Use the default mode, fork_mode instead

@koresar
Copy link

koresar commented Nov 26, 2014

@Unitech That's acceptable. Thanks.
Please, close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants