You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I never understood why domains were added to core.
There's a place for unified sync & async error handling for Node, and due to the way that state propagates through core, there at least need to be hooks exposed by core to facilitate this. uncaughtException is too gross-grained, not everybody uses (or likes) promises, try/catch + stream error listeners + callback convention is complicated to teach and learn and harder to master, etc. Probably the best effort at this so far is @piscisaureus and co's zones, but that solution has limitations that are going to be tough to resolve outside core.
I'm hopeful that @trevnorris's AsyncWrap can provide the foundation for a better / lower-impact way of building something useful along these lines in the future, and I consider domains a very useful failure that helped point to what AsyncWrap / AsyncListener should do.
Reacted by Eric Adum, Rodrigo Barbosa, 胡鹏 and Samuel Bodin
@tellnes I'll leave that to your own judgment. Doing it at require() time would get the message out most effectively but it might end up being extremely annoying.
If you do do it at require() time, you should also update lib/repl.js and make it load the domain module lazily.
I haven't read the whole thread, so sorry if I'm repeating things.
I want to say that I've recently been using domains to capture all calls to console.log, console.warn, etc. It is not a simple matter of monkey-patching these methods, since I also need to separate each call to its source (which is a unique context defined by my application).
So, I'm not using domains for handling errors at all. I don't even register an error event listener on my domains. I'm using domains as a way of execution context management.
This feature is necessary for my application to work, and so I hope that any replacement API to Domain will be able to cover my use-case...
BTW, I would be glad to know if there's a better way to do what I'm trying to do, other than abusing domains.
EDIT
I just wanted to add that it's not possible for me to improve my application to keep track of context manually, as my application keeps track of third-party user-code.
N.B.
I've also encountered the issues with native Promises. In my case, I fixed it by monkey-patching Promise (even though it might have a big performance hit):
Note that you do not need to patch the Promise constructor, because the executors run synchronously, but you can patch Promise.prototype.catch to work in the same way as the above patch on Promise.prototype.then. That being said, pretty certain Node version 8 has allowed domains to work with Promises, so the above patch may only be useful for Node.js versions < 8.
I just want to add my 2 cents to the long run discussion. I have a job. I want to keep my job. I really prefer to not have my server(s) crash, even if we use forever or supervisor to restart upon crashes.
Using the following allows us to avoid many crashes:
letdomain=require('domain');app.use(function(req,res,next){letd=domain.create();// create a new domain for this requestres.once('finish',function(){d.exit();d.removeAllListeners();});d.once('error',function(e){// log the issue right hereif(!res.headersSent){res.json({error: e.stack||e});}});d.run(next);// we invoke the next middleware});
we use domains in production. Hopefully no memory leaks though 😂
@ORESoftware I've moderated your previous comment. I found it to be inappropriate for this issue tracker. We intend on keeping this issue tracker professional and would appreciate if everyone who posts here does the same.
Reacted by Nicky McCurdy, Timothy Gu, Benjamin Gruenbaum, Anna Henningsen, Tobias Nießen and Nate Waddoups
@evanlucas censorship always appreciated, but I guess you're right, best to keep politics off of Github lol...@nickmmcurdy - you'd have to back up that statement - domains will fail in their intention if an error is raised for the wrong path of execution, and if it's easy to misuse them than that's also bad. But I don't think they are a hack perse, just perhaps imperfectly implemented.
@ORESoftware We have a Code of Conduct that asks you to be respectful of other people’s viewpoints and refrain from using language that “could reasonably be considered inappropriate in a professional setting”.
If you don’t feel comfortable with that, it might be easier to take a step back; Node’s project leadership is standing behind the choice to apply that CoC to our spaces.
Activity
juliangruber commentedon Dec 4, 2014
afaik no breaking changes will happen until v1
jonathanong commentedon Dec 4, 2014
just labeling something as deprecated is not a breaking change
juliangruber commentedon Dec 4, 2014
gotcha, 👍 from me, domains have only meant pain to me personally
rvagg commentedon Dec 4, 2014
I'm on board, I bet a bunch of TC members would be too, marking as tc-agenda
indutny commentedon Dec 4, 2014
+1
Marak commentedon Dec 4, 2014
I never understood why domains were added to core.
It seemed wrong at the time, and still seems equally as wrong.
For backwards compatibility, will it be possible to put this functionality into an npm module as a custom add-on? Does this already exist?
Fishrock123 commentedon Dec 4, 2014
+1 domains are confusing and I hear nothing but incompatibilities and edge cases
othiym23 commentedon Dec 4, 2014
+1 sad 🎺
@Marak
There's a place for unified sync & async error handling for Node, and due to the way that state propagates through core, there at least need to be hooks exposed by core to facilitate this.
uncaughtExceptionis too gross-grained, not everybody uses (or likes) promises, try/catch + stream error listeners + callback convention is complicated to teach and learn and harder to master, etc. Probably the best effort at this so far is @piscisaureus and co's zones, but that solution has limitations that are going to be tough to resolve outside core.I'm hopeful that @trevnorris's AsyncWrap can provide the foundation for a better / lower-impact way of building something useful along these lines in the future, and I consider domains a very useful failure that helped point to what AsyncWrap / AsyncListener should do.
bnoordhuis commentedon Dec 4, 2014
It would have to go through the TC but I don't think there is much opposition to deprecating domains. Who volunteers to follow up with a pull request?
tellnes commentedon Dec 4, 2014
@bnoordhuis A deprecation warning if you call
domain.create()? Or when you require it since it has side effects (acording to code comments).bnoordhuis commentedon Dec 4, 2014
@tellnes I'll leave that to your own judgment. Doing it at require() time would get the message out most effectively but it might end up being extremely annoying.
If you do do it at require() time, you should also update lib/repl.js and make it load the domain module lazily.
tellnes commentedon Dec 5, 2014
lib/repl.jsneeds to be changed anyway because it is callingdomain.create().rlidwka commentedon Dec 5, 2014
Is there a suitable replacement that could be used? Repl is a valid use-case for example.
tellnes commentedon Dec 5, 2014
@rlidwka Yes, the new tracing module in core. Please see my implementation in #75.
84 remaining items
bayov commentedon Jul 23, 2016
I haven't read the whole thread, so sorry if I'm repeating things.
I want to say that I've recently been using domains to capture all calls to
console.log,console.warn, etc. It is not a simple matter of monkey-patching these methods, since I also need to separate each call to its source (which is a unique context defined by my application).So, I'm not using domains for handling errors at all. I don't even register an
errorevent listener on my domains. I'm using domains as a way of execution context management.This feature is necessary for my application to work, and so I hope that any replacement API to
Domainwill be able to cover my use-case...BTW, I would be glad to know if there's a better way to do what I'm trying to do, other than abusing domains.
EDIT
I just wanted to add that it's not possible for me to improve my application to keep track of context manually, as my application keeps track of third-party user-code.
N.B.
I've also encountered the issues with native Promises. In my case, I fixed it by monkey-patching Promise (even though it might have a big performance hit):
ORESoftware commentedon Aug 4, 2017
@SosZ please search and read the whole thread before, I patched promises to use domains myself, in a much simpler way
Your code is a little bit of a horror show. What about this instead?
Note that you do not need to patch the Promise constructor, because the executors run synchronously, but you can patch
Promise.prototype.catchto work in the same way as the above patch onPromise.prototype.then. That being said, pretty certain Node version 8 has allowed domains to work with Promises, so the above patch may only be useful for Node.js versions < 8.ORESoftware commentedon Aug 4, 2017
I just want to add my 2 cents to the long run discussion. I have a job. I want to keep my job. I really prefer to not have my server(s) crash, even if we use
foreverorsupervisorto restart upon crashes.Using the following allows us to avoid many crashes:
we use domains in production. Hopefully no memory leaks though 😂
evanlucas commentedon Aug 8, 2017
@ORESoftware I've moderated your previous comment. I found it to be inappropriate for this issue tracker. We intend on keeping this issue tracker professional and would appreciate if everyone who posts here does the same.
nickserv commentedon Aug 8, 2017
Domains are still a hack, letting the process crash is often the better option especially with forever/supervisor.
ORESoftware commentedon Aug 8, 2017
@evanlucas censorship always appreciated, but I guess you're right, best to keep politics off of Github lol...@nickmmcurdy - you'd have to back up that statement - domains will fail in their intention if an error is raised for the wrong path of execution, and if it's easy to misuse them than that's also bad. But I don't think they are a hack perse, just perhaps imperfectly implemented.
addaleax commentedon Aug 8, 2017
@ORESoftware We have a Code of Conduct that asks you to be respectful of other people’s viewpoints and refrain from using language that “could reasonably be considered inappropriate in a professional setting”.
If you don’t feel comfortable with that, it might be easier to take a step back; Node’s project leadership is standing behind the choice to apply that CoC to our spaces.
ORESoftware commentedon Aug 8, 2017
Imma read the CoC right now to see if my microaggression actually violated it.
ORESoftware commentedon Aug 8, 2017
Yep, looks like I violated point 1
whoops, my bad fam
deps: V8: cherry-pick d2283ba066ba
deps: V8: cherry-pick 813066946968
deps: V8: cherry-pick d2283ba066ba
deps: V8: cherry-pick 813066946968