diff options
author | isaacs <i@izs.me> | 2013-03-09 07:00:21 -0800 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-03-09 07:00:21 -0800 |
commit | 80472bc301234d9dc4142e62bbffc4300fffdd83 (patch) | |
tree | 21303e63f897fd85740e0b054eddd56af8480489 | |
parent | 4d1e9e537029806cf873f21e41e92830c757e5cf (diff) | |
download | node-80472bc301234d9dc4142e62bbffc4300fffdd83.tar.gz |
domain: Fix double-exit on nested domains
Minor oversight in fix for #4953.
-rw-r--r-- | src/node.js | 4 | ||||
-rw-r--r-- | test/simple/test-domain-nested-throw.js | 42 |
2 files changed, 41 insertions, 5 deletions
diff --git a/src/node.js b/src/node.js index 9d6e75eef..49aedaee0 100644 --- a/src/node.js +++ b/src/node.js @@ -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; diff --git a/test/simple/test-domain-nested-throw.js b/test/simple/test-domain-nested-throw.js index e1d3bb2d9..e11948667 100644 --- a/test/simple/test-domain-nested-throw.js +++ b/test/simple/test-domain-nested-throw.js @@ -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(); |