• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const domain = require('domain');
5
6// Make sure that the domains stack is cleared after a top-level domain
7// error handler exited gracefully.
8const d = domain.create();
9
10d.on('error', common.mustCall(() => {
11  // Scheduling a callback with process.nextTick _could_ enter a _new_ domain,
12  // but domain's error handlers are called outside of their domain's context.
13  // So there should _no_ domain on the domains stack if the domains stack was
14  // cleared properly when the domain error handler was called.
15  process.nextTick(() => {
16    if (domain._stack.length !== 0) {
17      // Do not use assert to perform this test: this callback runs in a
18      // different callstack as the original process._fatalException that
19      // handled the original error, thus throwing here would trigger another
20      // call to process._fatalException, and so on recursively and
21      // indefinitely.
22      console.error('domains stack length should be 0, but instead is:',
23                    domain._stack.length);
24      process.exit(1);
25    }
26  });
27}));
28
29d.run(() => {
30  throw new Error('Error from domain');
31});
32