http://stackoverflow.com/questions/7310521/node-js-best-practice-exception-handling
http://stackoverflow.com/questions/5999373/how-do-i-prevent-node-js-from-crashing-try-catch-doesnt-work
http://stackoverflow.com/questions/7310521/node-js-best-practice-exception-handling
Ah, that's a tricky question. First of all, domains approach differs from forever in that it doesn't force you to restart the whole Node process. Say, for example, your Node application processes requests coming from several clients simultaneously. By carefully configuring your domains you (at least, in theory) will be able to prevent other requests from failing when one of the requests throws an error.
However, in practice to get domains work some components of your application has to be domain-aware. That applies to third-party components, too. For example, a database connection module that uses a pool of connections internally, should not wrap them into it's own domain, but rather check if the callback has a domain attached to it already. Otherwise, an exception thrown in a database code would be caught in a module's own domain and your domain wouldn't know about it. So, in order to use domains with third-party code you have to heck first if that code was written with domains in mind.
forever simply restarts your application whenever it crashes. It sounds like a worse idea than domains, but it also doesn't impose any specific requirements over a third-party code. Thus, you can use whatever library or module you want. You also don't have to put any complicated error recovery logic into your code. Sometimes having a simple codebase is more important than having non-failing yet complex one.
As for process.on('uncaughtException') I wouldn't use it. It's deprecated now, so it will probably be removed at some point.
Here's my breakdown:
forever
Pros:
lets you keep your codebase simpler and smaller
allows you to write your application logic first and think about error handling later
Cons:
Single uncaught exception causes all other requests to fail
Use when:
Your Node process and your requests are cheap
Clients can retry on error
domains
Pros:
Broken request doesn't break other clients
Node process stays up longer reducing your overall downtime
See also domains+cluster combo (Thanks, Isaac!)
Cons:
Can be used with domain-aware 3rd-party libraries
Requires additional logic in your program
Use when:
Your requests or your Node process are expensive (e.g. file uploads, streaming data)
Single-node uptime is important
process.on('uncaughtException') don't use it.
Notes
1. Isaac Z. Schlueter and Felix Geisendörfer talked about domains in 13th episode of NodeUp
2. There's a recent article explaining the difference between forever and Unix's systemd. You may find it useful.
Using Systemd
https://rocketeer.be/articles/deploying-node-js-with-systemd/
But aptible container (mostly ubuntu ?) normal version is Ubuntu 14.04 (no systemd support/build-in/default).
=> Custom image: https://www.aptible.com/support/topics/enclave/how-to-deploy-from-private-repository/. Need host private docker app image on another service (HIPAA Compliance). quay.io ?
No CentOS, RHEL image for aptible ?
http://stackoverflow.com/questions/5999373/how-do-i-prevent-node-js-from-crashing-try-catch-doesnt-work
http://stackoverflow.com/questions/7310521/node-js-best-practice-exception-handling
Ah, that's a tricky question. First of all, domains approach differs from forever in that it doesn't force you to restart the whole Node process. Say, for example, your Node application processes requests coming from several clients simultaneously. By carefully configuring your domains you (at least, in theory) will be able to prevent other requests from failing when one of the requests throws an error.
However, in practice to get domains work some components of your application has to be domain-aware. That applies to third-party components, too. For example, a database connection module that uses a pool of connections internally, should not wrap them into it's own domain, but rather check if the callback has a domain attached to it already. Otherwise, an exception thrown in a database code would be caught in a module's own domain and your domain wouldn't know about it. So, in order to use domains with third-party code you have to heck first if that code was written with domains in mind.
forever simply restarts your application whenever it crashes. It sounds like a worse idea than domains, but it also doesn't impose any specific requirements over a third-party code. Thus, you can use whatever library or module you want. You also don't have to put any complicated error recovery logic into your code. Sometimes having a simple codebase is more important than having non-failing yet complex one.
As for process.on('uncaughtException') I wouldn't use it. It's deprecated now, so it will probably be removed at some point.
Here's my breakdown:
forever
Pros:
lets you keep your codebase simpler and smaller
allows you to write your application logic first and think about error handling later
Cons:
Single uncaught exception causes all other requests to fail
Use when:
Your Node process and your requests are cheap
Clients can retry on error
domains
Pros:
Broken request doesn't break other clients
Node process stays up longer reducing your overall downtime
See also domains+cluster combo (Thanks, Isaac!)
Cons:
Can be used with domain-aware 3rd-party libraries
Requires additional logic in your program
Use when:
Your requests or your Node process are expensive (e.g. file uploads, streaming data)
Single-node uptime is important
process.on('uncaughtException') don't use it.
Notes
1. Isaac Z. Schlueter and Felix Geisendörfer talked about domains in 13th episode of NodeUp
2. There's a recent article explaining the difference between forever and Unix's systemd. You may find it useful.
Using Systemd
https://rocketeer.be/articles/deploying-node-js-with-systemd/
But aptible container (mostly ubuntu ?) normal version is Ubuntu 14.04 (no systemd support/build-in/default).
=> Custom image: https://www.aptible.com/support/topics/enclave/how-to-deploy-from-private-repository/. Need host private docker app image on another service (HIPAA Compliance). quay.io ?
No CentOS, RHEL image for aptible ?
Comments
Post a Comment