coopernurse / node-pool

Generic resource pooling for node.js
2.38k stars 259 forks source link

Use domain.bind to preserve domain context #152

Closed LewisJEllis closed 8 years ago

LewisJEllis commented 8 years ago

This is a case of the userland queueing problem. We don't have automatic implicit binding here, so we need to do explicit binding, as described in the domain docs.

I'm aware that domains are deprecated, people should avoid using them, a replacement is coming, etc, but there are use cases where they are absolutely necessary and losing the domain context can lead to state mismatches. This fix will be helpful for any projects that use node-pool (or anything depending on node-pool) and any sort of domain context pattern (or any of several error reporting and APM tools which do).

For reference, the widely-used redis, cassandra, mysql, and postgres drivers handle this correctly, among others.

sandfox commented 8 years ago

Thanks for this, I'm not very familiar with domains, so I'm going to trust this makes sense. (I've done some reading of the docs and it looks about right)

I'm currently working on v3 of the pool, but I'll try and get this and some other fixes released this weekend.

LewisJEllis commented 8 years ago

Sounds great, thanks!

If you're looking to understand domains a bit more, I can recommend this post for a good primer (less referencey than the docs). I also put together some related examples/explanations here if you want to explore the cases that this solves.

LewisJEllis commented 7 years ago

Thanks for the merge & release!