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>
31 lines
795 B
JavaScript
31 lines
795 B
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, 'SIGINT');
|
|
assert.strictEqual(code, null);
|
|
}));
|
|
}
|
|
|
|
function main() {
|
|
// Deactivate colors even if the tty does support colors.
|
|
process.env.NODE_DISABLE_COLORS = '1';
|
|
process.kill(process.pid, 'SIGINT');
|
|
while (true) {}
|
|
}
|