mirror of https://github.com/lukechilds/node.git
Browse Source
v4.xf2a45caf2e
contained a test for a regression that had been introduced by the original change that77a10ed05f
ported. While77a10ed05f
did not contain that regression, the test thatf2a45caf2e
contained should still be in the code base to prevent any regression from happening in the future. Original message for the commit that contained the test: domains: fix stack clearing after error handledcaeb67735b
introduced a regression where the domains stack would not be cleared after an error had been handled by the top-level domain. This change clears the domains stack regardless of the position of the active domain in the stack. PR: #9364 PR-URL: https://github.com/joyent/node/pull/9364 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Julien Gilli <julien.gilli@joyent.com> PR: #3356 PR-URL: https://github.com/nodejs/node/pull/3356 Reviewed-By: Ben Noordhuis <ben@strongloop.com>
Jonas Dohse
9 years ago
committed by
James M Snell
1 changed files with 34 additions and 0 deletions
@ -0,0 +1,34 @@ |
|||
'use strict'; |
|||
|
|||
const common = require('../common'); |
|||
const domain = require('domain'); |
|||
|
|||
/* |
|||
* Make sure that the domains stack is cleared after a top-level domain |
|||
* error handler exited gracefully. |
|||
*/ |
|||
const d = domain.create(); |
|||
|
|||
d.on('error', common.mustCall(function() { |
|||
process.nextTick(function() { |
|||
// Scheduling a callback with process.nextTick will enter a _new_ domain,
|
|||
// and the callback will be called after the domain that handled the error
|
|||
// was exited. So there should be only one domain on the domains stack if
|
|||
// the domains stack was cleared properly when the domain error handler
|
|||
// returned.
|
|||
if (domain._stack.length !== 1) { |
|||
// Do not use assert to perform this test: this callback runs in a
|
|||
// different callstack as the original process._fatalException that
|
|||
// handled the original error, thus throwing here would trigger another
|
|||
// call to process._fatalException, and so on recursively and
|
|||
// indefinitely.
|
|||
console.error('domains stack length should be 1, but instead is:', |
|||
domain._stack.length); |
|||
process.exit(1); |
|||
} |
|||
}); |
|||
})); |
|||
|
|||
d.run(function() { |
|||
throw new Error('Error from domain'); |
|||
}); |
Loading…
Reference in new issue