mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +00:00

Before this change, domains' error handlers would run with the corresponding domain as the active domain. This creates the possibility for domains' error handlers to call themselves recursively if an event emitter created in the error handler emits an error, or if the error handler throws an error. This change sets the active domain to be the domain's parent (or null if the domain for which the error handler is called has no parent) to prevent that from happening. Fixes: https://github.com/nodejs/node/issues/26086 PR-URL: https://github.com/nodejs/node/pull/26211 Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const domain = require('domain');
|
|
|
|
/*
|
|
* Make sure that when an erorr is thrown from a nested domain, its error
|
|
* handler runs outside of that domain, but within the context of any parent
|
|
* domain.
|
|
*/
|
|
|
|
const d = domain.create();
|
|
const d2 = domain.create();
|
|
|
|
d2.on('error', common.mustCall((err) => {
|
|
if (domain._stack.length !== 1) {
|
|
console.error('domains stack length should be 1 but is %d',
|
|
domain._stack.length);
|
|
process.exit(1);
|
|
}
|
|
|
|
if (process.domain !== d) {
|
|
console.error('active domain should be %j but is %j', d, process.domain);
|
|
process.exit(1);
|
|
}
|
|
|
|
process.nextTick(() => {
|
|
if (domain._stack.length !== 1) {
|
|
console.error('domains stack length should be 1 but is %d',
|
|
domain._stack.length);
|
|
process.exit(1);
|
|
}
|
|
|
|
if (process.domain !== d) {
|
|
console.error('active domain should be %j but is %j', d,
|
|
process.domain);
|
|
process.exit(1);
|
|
}
|
|
});
|
|
}));
|
|
|
|
d.run(() => {
|
|
d2.run(() => {
|
|
throw new Error('oops');
|
|
});
|
|
});
|