mirror of
https://github.com/nodejs/node-v0.x-archive.git
synced 2026-04-28 03:01:10 -04:00
domain: Fix double-exit on nested domains
Minor oversight in fix for #4953.
This commit is contained in:
@@ -258,7 +258,9 @@
|
||||
// The domain error handler threw! oh no!
|
||||
// See if another domain can catch THIS error,
|
||||
// or else crash on the original one.
|
||||
domainStack.pop();
|
||||
// If the user already exited it, then don't double-exit.
|
||||
if (domain === domainModule.active)
|
||||
domainStack.pop();
|
||||
if (domainStack.length) {
|
||||
var parentDomain = domainStack[domainStack.length - 1];
|
||||
process.domain = domainModule.active = parentDomain;
|
||||
|
||||
@@ -24,6 +24,34 @@ var assert = require('assert');
|
||||
|
||||
var domain = require('domain');
|
||||
|
||||
var dispose;
|
||||
switch (process.argv[2]) {
|
||||
case 'true':
|
||||
dispose = true;
|
||||
break;
|
||||
case 'false':
|
||||
dispose = false;
|
||||
break;
|
||||
default:
|
||||
parent();
|
||||
return;
|
||||
}
|
||||
|
||||
function parent() {
|
||||
var node = process.execPath;
|
||||
var spawn = require('child_process').spawn;
|
||||
var opt = { stdio: 'inherit' };
|
||||
var child = spawn(node, [__filename, 'true'], opt);
|
||||
child.on('exit', function(c) {
|
||||
assert(!c);
|
||||
child = spawn(node, [__filename, 'false'], opt);
|
||||
child.on('exit', function(c) {
|
||||
assert(!c);
|
||||
console.log('ok');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var gotDomain1Error = false;
|
||||
var gotDomain2Error = false;
|
||||
|
||||
@@ -44,8 +72,11 @@ function inner(throw1, throw2) {
|
||||
var domain1 = domain.createDomain();
|
||||
|
||||
domain1.on('error', function (err) {
|
||||
console.error('domain 1 error');
|
||||
if (gotDomain1Error) process.exit(1);
|
||||
if (gotDomain1Error) {
|
||||
console.error('got domain 1 twice');
|
||||
process.exit(1);
|
||||
}
|
||||
if (dispose) domain1.dispose();
|
||||
gotDomain1Error = true;
|
||||
throw2();
|
||||
});
|
||||
@@ -59,7 +90,10 @@ function outer() {
|
||||
var domain2 = domain.createDomain();
|
||||
|
||||
domain2.on('error', function (err) {
|
||||
console.error('domain 2 error');
|
||||
if (gotDomain2Error) {
|
||||
console.error('got domain 2 twice');
|
||||
process.exit(1);
|
||||
}
|
||||
gotDomain2Error = true;
|
||||
});
|
||||
|
||||
@@ -73,7 +107,7 @@ process.on('exit', function() {
|
||||
assert(gotDomain2Error);
|
||||
assert(threw1);
|
||||
assert(threw2);
|
||||
console.log('ok');
|
||||
console.log('ok', dispose);
|
||||
});
|
||||
|
||||
outer();
|
||||
|
||||
Reference in New Issue
Block a user