File tree Expand file tree Collapse file tree 5 files changed +90
-5
lines changed Expand file tree Collapse file tree 5 files changed +90
-5
lines changed Original file line number Diff line number Diff line change @@ -4059,6 +4059,10 @@ This property refers to the value of underlying file descriptor of
40594059` process .stderr ` . The value is fixed at ` 2 ` . In [` Worker ` ][] threads,
40604060this field does not exist.
40614061
4062+ ## ` process .startTraceSigInt `
4063+
4064+ Prints a stack trace on ` SIGINT ` .
4065+
40624066## ` process .stdin `
40634067
40644068* {Stream}
@@ -4168,6 +4172,10 @@ false
41684172
41694173See the [TTY][] documentation for more information.
41704174
4175+ ## ` process .stopTraceSigInt `
4176+
4177+ Stop Printing a stack trace on ` SIGINT ` .
4178+
41714179## ` process .throwDeprecation `
41724180
41734181<!-- YAML
Original file line number Diff line number Diff line change @@ -382,14 +382,27 @@ function setupCodeCoverage() {
382382 }
383383}
384384
385+
386+ let sigintWatchdog ;
387+ function getSigintWatchdog ( ) {
388+ if ( ! sigintWatchdog ) {
389+ const { SigintWatchdog } = require ( 'internal/watchdog' ) ;
390+ sigintWatchdog = new SigintWatchdog ( ) ;
391+ }
392+ return sigintWatchdog ;
393+ }
394+
385395function setupStacktracePrinterOnSigint ( ) {
396+ process . startTraceSigInt = function ( ) {
397+ getSigintWatchdog ( ) . start ( ) ;
398+ } ;
399+ process . stopTraceSigInt = function ( ) {
400+ getSigintWatchdog ( ) . stop ( ) ;
401+ } ;
386402 if ( ! getOptionValue ( '--trace-sigint' ) ) {
387403 return ;
388404 }
389- const { SigintWatchdog } = require ( 'internal/watchdog' ) ;
390-
391- const watchdog = new SigintWatchdog ( ) ;
392- watchdog . start ( ) ;
405+ process . startTraceSigInt ( ) ;
393406}
394407
395408function initializeReport ( ) {
Original file line number Diff line number Diff line change @@ -53,7 +53,6 @@ class SigintWatchdog extends TraceSigintWatchdog {
5353 }
5454}
5555
56-
5756module . exports = {
5857 SigintWatchdog,
5958} ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const { mustCall } = require ( '../common' ) ;
4+ const childProcess = require ( 'child_process' ) ;
5+ const assert = require ( 'assert' ) ;
6+
7+ if ( ! process . env . CHILD ) {
8+ const cp = childProcess . spawn (
9+ process . execPath ,
10+ [ __filename ] ,
11+ {
12+ env : { ...process . env , CHILD : '1' } ,
13+ } ) ;
14+ let data ;
15+ cp . stderr . on ( 'data' , ( chunk ) => {
16+ data = data ? data + chunk : chunk ;
17+ } ) ;
18+ cp . stderr . on ( 'end' , ( ) => {
19+ console . log ( data ) ;
20+ assert . strictEqual ( / S I G I N T / . test ( data . toString ( ) ) , true ) ;
21+ } ) ;
22+ cp . on ( 'exit' , mustCall ( ( code , signal ) => {
23+ assert . strictEqual ( signal , 'SIGINT' ) ;
24+ assert . strictEqual ( code , null ) ;
25+ } ) ) ;
26+ } else {
27+ process . startTraceSigInt ( ) ;
28+ // Deactivate colors even if the tty does support colors.
29+ process . env . NODE_DISABLE_COLORS = '1' ;
30+ process . kill ( process . pid , 'SIGINT' ) ;
31+ while ( true ) ;
32+ }
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const { mustCall } = require ( '../common' ) ;
4+ const childProcess = require ( 'child_process' ) ;
5+ const assert = require ( 'assert' ) ;
6+
7+ if ( ! process . env . CHILD ) {
8+ {
9+ const cp = childProcess . spawn (
10+ process . execPath ,
11+ [ '--trace-sigint' , __filename ] ,
12+ {
13+ env : { ...process . env , CHILD : '1' } ,
14+ } ) ;
15+ let data ;
16+ cp . stderr . on ( 'data' , ( chunk ) => {
17+ data = data ? data + chunk : chunk ;
18+ } ) ;
19+ cp . stderr . on ( 'end' , ( ) => {
20+ assert . strictEqual ( data === undefined , true ) ;
21+ } ) ;
22+ cp . on ( 'exit' , mustCall ( ( code , signal ) => {
23+ assert . strictEqual ( signal , 'SIGINT' ) ;
24+ assert . strictEqual ( code , null ) ;
25+ } ) ) ;
26+ }
27+ } else {
28+ process . stopTraceSigInt ( ) ;
29+ // Deactivate colors even if the tty does support colors.
30+ process . env . NODE_DISABLE_COLORS = '1' ;
31+ process . kill ( process . pid , 'SIGINT' ) ;
32+ while ( true ) ;
33+ }
You can’t perform that action at this time.
0 commit comments