brianc/node-domain-middleware

Is the use of process.domain.intercept?

ix-xerri opened this issue · 2 comments

I am using this middleware and one particular request is generating an exception. At the moment I am not using intercept, I'm just letting errors bubble up through the callback and have express's error handler handle them. In the error handler, process.domain is undefined.

This might have something to do with how my route is structured but I'm not sure. I have setup up multiple functions inside the route and they call each other as callbacks to avoid having nested callbacks.

Hi! I'm not sure your question exactly. Are you asking if you should use process.domain.intercept? In my experience it never hurts to use it, and actually helps in most cases. Especially if you use c++ modules, they often unbind from the domain. I know my pg module can also unbind from the domain if you are using the connection pool. Domains are a pain to use. I actually made https://github.com/brianc/okay and use it extensively in all of my code. It does the domain interception for you if you are using domains.

Does that help?

It does. I would have though that wrapping the first callback with d.intercept than that would be sufficient. I assumed that if a nested callback generated an error, that would be caught by the d.intercept used with the parent callback. From you explanation it seems that that is not the case and one must wrap every callback with d.intercept right?