Skip to content

Instantly share code, notes, and snippets.

@cxreg
Created February 2, 2013 21:13
Show Gist options
  • Save cxreg/4699265 to your computer and use it in GitHub Desktop.
Save cxreg/4699265 to your computer and use it in GitHub Desktop.
// == test code ==
var redis = require('redis');
var domain = require('domain');
var c = redis.createClient();
for (var n = 0; n < 10; n++) {
var d = domain.create();
d.on('error', function() {
console.log('caught, domain stack is ' + domain._stack.length);
});
d.run(function() {
c.get('foo', function(err, reply) {
throw new Error('fatal');
});
});
}
/* output
caught, domain stack is 1
caught, domain stack is 2
caught, domain stack is 3
caught, domain stack is 4
caught, domain stack is 5
caught, domain stack is 6
caught, domain stack is 7
caught, domain stack is 8
caught, domain stack is 9
caught, domain stack is 10
*/
/* patch to fix
@@ -522,6 +522,7 @@
} catch (err) {
if (process.domain) {
process.domain.emit('error', err);
+ process.domain.exit();
} else {
process.nextTick(function () {
throw err;
*/
/* output with fix
caught, domain stack is 1
caught, domain stack is 1
caught, domain stack is 1
caught, domain stack is 1
caught, domain stack is 1
caught, domain stack is 1
caught, domain stack is 1
caught, domain stack is 1
caught, domain stack is 1
caught, domain stack is 1
*/
@vpArth
Copy link

vpArth commented Oct 17, 2013

Hi, why this code does not work for me?
I have node-redis 0.8.6 from registry.npmjs.org
And your snippet crash nodejs app, domain not caught exception...
How can I get access to domains compatible version of node-redis?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment