Forrest L Norvell
Node.js agent engineer
| E forr...@newrelic.com (mailto:forr...@newrelic.com) | C (415) 823-6356 | T 
@othiym23 (http://twitter.com/othiym23) | G github.com/othiym23 
(https://github.com/othiym23) | W newrelic.com (http://newrelic.com/)
( ( *))  New Relic





On Wednesday, November 14, 2012 at 1:35 PM, pie_lard wrote:

> Suppose node were changed to remove the feature that lets domains track 
> EventEmitters.  So domain.add(), .remove() and .members would all be removed. 
>  The code that automatically adds new EventEmitters to the active domain (if 
> there is one) would also be deleted.  Finally, suppose .bind() and 
> .intercept() were also removed.

As an aside, you should only have to call domain.{add,remove} on a handle or an 
emitter yourself under very specific (and rare) conditions.
> That would just leave domain.run() - plus the ability to create new domains 
> and possibly nest them.
>  
> Would that be enough to effectively recreate synchronous stack-based 
> exception handling?
No, and I'll explain why below.  
> My answer would be yes - and in fact it would remove my connection-pool 
> problem altogether without any need for the 3rd-party module authors to 
> change anything.
>  
> To put it another way; in what real-world circumstances would you need the 
> features I just removed?
>  
> Please understand I ask this as a bit of a node noob ;)  It's not a criticism 
> of domains - I would like someone to explain why I'm wrong about this.
The problem is it's impossible to know in advance whether a chunk of code is 
going to use EventEmitters or not, and without domain code there to wrap them, 
you'd lose the necessary state to tie a specific request to a specific domain. 
Consider the following (buggy / incomplete) Express handler:

app.get('/test', function (req, res) {
  var d = domain.create();
  d.on('error', function (error) { res.send(500, {"content-type":"text/plain"}, 
error.stack); });
  d.run(function () {
    fs.readFile(FILENAME, 'utf-8', function (err, contents) {
      // process.domain should be available here
      res.send(contents.replace(/:/gm, '/'));
    });
  });
});





The call to res.send is going to happen several passes through the event loop 
after the initial handler is called. It's entirely possible that in the time 
the file is read from disk, another several requests to that handler are going 
to have come in to the server. Without dealing with the EventEmitters, how will 
any errors emitted inside the fs.readFile callback be connected back to the 
enclosing domain?

F

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to