Reputation: 797
In the accepted answer to this question the guy recommends against using domains with throwing exceptions from them because, he says, it will cause memleaks and instability. But this is the way I was going to use domains. Now I'm confused. Is he right?
Upvotes: 2
Views: 125
Reputation: 4373
Unlike that answer asserts, there is no guarantee that it will cause memory leaks and instability. But it is hard to guarantee that you can handle the exception without causing memory leaks and instability.
I believe the core of the confusion around exception handling stems from this wording from the Node.js documentation:
By the very nature of how throw works in JavaScript, there is almost never any way to safely "pick up where you left off", without leaking references, or creating some other sort of undefined brittle state.
The safest way to respond to a thrown error is to shut down the process.
http://nodejs.org/api/domain.html
In reality, there's nothing special about JavaScript that makes exceptions particularly dangerous. The fact is, exceptions have potential to be dangerous in any language. The point is to consider carefully what side-effects your application is causing, and whether you're doing anything that could be dangerous if it were to stop half-way through (hint: you probably are).
This design guide from Joyent makes the distinction between "programmer errors" and "operational errors". In answer of your question, this guide advocates not handling programmer errors (including reading a property of undefined), and asserts that since Domains and process.on('uncaughtException')
are primarily geared toward these kinds of errors, they should be avoided.
Upvotes: 3
Reputation: 6986
i think the best way of using domains is to catch out the error. Also i recommend to restart nodejs processes at least once per few hours. And use clustering so we have a number of nodejs projects sharing and serving on the same port.
Upvotes: 0