Domain for every worker?

66 views
Skip to first unread message

Honigbaum

unread,
Aug 10, 2012, 8:01:31 AM8/10/12
to nod...@googlegroups.com
Hello, 

my node.js application uses the cluster module for forking workers and I want to use the new domain module to catch all uncaught exceptions.

Is there a way to fork each worker in an own domain? I tried to wrap the whole application in an domain, but then the error handler is called for each worker.


Thank you
Torben

Dan Milon

unread,
Aug 10, 2012, 8:32:03 AM8/10/12
to nod...@googlegroups.com
How did you implement this exactly? (gist?)
You should be able to create a domain inside the slave code that will
fire whenever this specific slave throws.

danmilon.
> --
> 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 nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

Honigbaum

unread,
Aug 10, 2012, 8:38:20 AM8/10/12
to nod...@googlegroups.com
Hello,

I tried it like this https://gist.github.com/3313918

Or is it a problem that I assign ever domain to the same var?


Torben

Dan Milon

unread,
Aug 10, 2012, 9:40:04 AM8/10/12
to nod...@googlegroups.com
That is wrong.

The domain creation should be at the code of the slave.
the slaves are the actual servers that share the port. Thats where the
errors occur.
master is a mere coordinator.

Slave code is at the else part of cluster.isMaster.

Also you create the server without regard of weather the process is
master / slave. Functionally its the same (since you only listen for the
slave) but i consider it bad practice.

So the server creation code should go at the else part also.

danmilon.
> https://github.com/joyent/node/wiki/Mailing-List-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 nod...@googlegroups.com
> <javascript:>
> > To unsubscribe from this group, send email to
> > nodejs+un...@googlegroups.com <javascript:>
> > For more options, visit this group at
> > http://groups.google.com/group/nodejs?hl=en?hl=en
> <http://groups.google.com/group/nodejs?hl=en?hl=en>

Honigbaum

unread,
Aug 10, 2012, 10:16:41 AM8/10/12
to nod...@googlegroups.com
Ah, you're right.

Dan Milon

unread,
Aug 10, 2012, 10:48:17 AM8/10/12
to nod...@googlegroups.com
Almost correct.

But you have to add the 'error' listener before the .run call.
.run will immediately call the provided function, so if an error happens
immediately, you wont catch it.

source:
Domain.prototype.run = function(fn) {
return this.bind(fn)();
};

bind here refers to the documented domain#bind method.

Good luck.
danmilon.
Message has been deleted

Honigbaum

unread,
Aug 10, 2012, 11:43:43 AM8/10/12
to nod...@googlegroups.com
Thank you!

I've refactored my code. 

Does anyone know if it is possible to render an error page with express, when an uncaught error is catched by the error listener of the domain? Or is it necessary to create a separate domain for ever request?

Torben 
Reply all
Reply to author
Forward
0 new messages