summaryrefslogtreecommitdiff
path: root/test/pseudo-tty/test-trace-sigint.js
diff options
context:
space:
mode:
authorlegendecas <legendecas@gmail.com>2019-08-19 21:03:08 +0800
committerlegendecas <legendecas@gmail.com>2020-01-28 13:52:27 +0800
commit7b7e7bd185aa606cf2845747dd3844a9b12ec9ab (patch)
tree5081e7a080edf45d2b5f82039e0d014c0ab46d96 /test/pseudo-tty/test-trace-sigint.js
parent78743f8e3912fa04670ceab5365f081b3079507b (diff)
downloadnode-new-7b7e7bd185aa606cf2845747dd3844a9b12ec9ab.tar.gz
src,lib: make ^C print a JS stack trace
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>
Diffstat (limited to 'test/pseudo-tty/test-trace-sigint.js')
-rw-r--r--test/pseudo-tty/test-trace-sigint.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/pseudo-tty/test-trace-sigint.js b/test/pseudo-tty/test-trace-sigint.js
new file mode 100644
index 0000000000..8b539bfc88
--- /dev/null
+++ b/test/pseudo-tty/test-trace-sigint.js
@@ -0,0 +1,30 @@
+'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) {}
+}