mirror of
https://github.com/nodejs/node.git
synced 2024-11-29 23:16:30 +01:00
7b7e7bd185
If terminating the process with ctrl-c / SIGINT, prints a JS stacktrace leading up to the currently executing code. The feature would be enabled under option `--trace-sigint`. Conditions of no stacktrace on sigint: - has (an) active sigint listener(s); - main thread is idle (i.e. uv polling), a message instead of stacktrace would be printed. PR-URL: https://github.com/nodejs/node/pull/29207 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Christopher Hiller <boneskull@boneskull.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
const { mustCall } = require('../common');
|
|
const childProcess = require('child_process');
|
|
const assert = require('assert');
|
|
|
|
if (process.env.CHILD === 'true') {
|
|
main();
|
|
} else {
|
|
// Use inherited stdio child process to prevent test tools from determining
|
|
// the case as crashed from SIGINT
|
|
const cp = childProcess.spawn(
|
|
process.execPath,
|
|
['--trace-sigint', __filename],
|
|
{
|
|
env: { ...process.env, CHILD: 'true' },
|
|
stdio: 'inherit'
|
|
});
|
|
cp.on('exit', mustCall((code, signal) => {
|
|
assert.strictEqual(signal, null);
|
|
assert.strictEqual(code, 0);
|
|
}));
|
|
}
|
|
|
|
function main() {
|
|
// Deactivate colors even if the tty does support colors.
|
|
process.env.NODE_DISABLE_COLORS = '1';
|
|
|
|
const noop = mustCall(() => {
|
|
process.exit(0);
|
|
});
|
|
process.on('SIGINT', noop);
|
|
// Try testing re-add 'SIGINT' listeners
|
|
process.removeListener('SIGINT', noop);
|
|
process.on('SIGINT', noop);
|
|
|
|
process.kill(process.pid, 'SIGINT');
|
|
setTimeout(() => { assert.fail('unreachable path'); }, 10 * 1000);
|
|
}
|