Created
February 2, 2013 21:13
-
-
Save cxreg/4699265 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// == 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 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?