2015-10-13 18:38:45 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const domain = require('domain');
|
|
|
|
|
2020-10-03 13:01:57 -07:00
|
|
|
// Make sure that the domains stack is cleared after a top-level domain
|
|
|
|
// error handler exited gracefully.
|
2015-10-13 18:38:45 -07:00
|
|
|
const d = domain.create();
|
|
|
|
|
2017-11-27 17:53:12 +09:00
|
|
|
d.on('error', common.mustCall(() => {
|
2019-02-19 14:29:31 -08:00
|
|
|
// Scheduling a callback with process.nextTick _could_ enter a _new_ domain,
|
|
|
|
// but domain's error handlers are called outside of their domain's context.
|
|
|
|
// So there should _no_ domain on the domains stack if the domains stack was
|
|
|
|
// cleared properly when the domain error handler was called.
|
2017-11-27 17:53:12 +09:00
|
|
|
process.nextTick(() => {
|
2019-02-19 14:29:31 -08:00
|
|
|
if (domain._stack.length !== 0) {
|
2015-10-13 18:38:45 -07:00
|
|
|
// 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.
|
2019-02-19 14:29:31 -08:00
|
|
|
console.error('domains stack length should be 0, but instead is:',
|
2016-04-25 23:32:35 -07:00
|
|
|
domain._stack.length);
|
2015-10-13 18:38:45 -07:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2017-11-27 17:53:12 +09:00
|
|
|
d.run(() => {
|
2015-10-13 18:38:45 -07:00
|
|
|
throw new Error('Error from domain');
|
|
|
|
});
|