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
4059
4059
` process .stderr ` . The value is fixed at ` 2 ` . In [` Worker ` ][] threads,
4060
4060
this field does not exist.
4061
4061
4062
+ ## ` process .startTraceSigInt `
4063
+
4064
+ Prints a stack trace on ` SIGINT ` .
4065
+
4062
4066
## ` process .stdin `
4063
4067
4064
4068
* {Stream}
@@ -4168,6 +4172,10 @@ false
4168
4172
4169
4173
See the [TTY][] documentation for more information.
4170
4174
4175
+ ## ` process .stopTraceSigInt `
4176
+
4177
+ Stop Printing a stack trace on ` SIGINT ` .
4178
+
4171
4179
## ` process .throwDeprecation `
4172
4180
4173
4181
<!-- YAML
Original file line number Diff line number Diff line change @@ -382,14 +382,27 @@ function setupCodeCoverage() {
382
382
}
383
383
}
384
384
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
+
385
395
function setupStacktracePrinterOnSigint ( ) {
396
+ process . startTraceSigInt = function ( ) {
397
+ getSigintWatchdog ( ) . start ( ) ;
398
+ } ;
399
+ process . stopTraceSigInt = function ( ) {
400
+ getSigintWatchdog ( ) . stop ( ) ;
401
+ } ;
386
402
if ( ! getOptionValue ( '--trace-sigint' ) ) {
387
403
return ;
388
404
}
389
- const { SigintWatchdog } = require ( 'internal/watchdog' ) ;
390
-
391
- const watchdog = new SigintWatchdog ( ) ;
392
- watchdog . start ( ) ;
405
+ process . startTraceSigInt ( ) ;
393
406
}
394
407
395
408
function initializeReport ( ) {
Original file line number Diff line number Diff line change @@ -53,7 +53,6 @@ class SigintWatchdog extends TraceSigintWatchdog {
53
53
}
54
54
}
55
55
56
-
57
56
module . exports = {
58
57
SigintWatchdog,
59
58
} ;
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