Skip to content

Commit 196a470

Browse files
committed
src: add --disable-sigusr1 to prevent signal i/o thread
This commit adds a new flag `--disable-sigusr1` to prevent the SignalIOThread to be up listening the SIGUSR1 events and then starting the debugging session.
1 parent 98d4ebc commit 196a470

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

doc/api/cli.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,17 @@ Disable the `Object.prototype.__proto__` property. If `mode` is `delete`, the
574574
property is removed entirely. If `mode` is `throw`, accesses to the
575575
property throw an exception with the code `ERR_PROTO_ACCESS`.
576576

577+
### `--disable-sigusr1`
578+
579+
<!-- YAML
580+
added: REPLACEME
581+
-->
582+
583+
> Stability: 1.2 - Release candidate
584+
585+
Disable the ability of starting a debugging session by sending a
586+
`SIGUSR1` signal to the process.
587+
577588
### `--disable-warning=code-or-type`
578589

579590
> Stability: 1.1 - Active development
@@ -1447,6 +1458,7 @@ added: v7.6.0
14471458

14481459
Set the `host:port` to be used when the inspector is activated.
14491460
Useful when activating the inspector by sending the `SIGUSR1` signal.
1461+
Except when [`--disable-sigusr1`][] is passed.
14501462

14511463
Default host is `127.0.0.1`. If port `0` is specified,
14521464
a random available port will be used.
@@ -3073,6 +3085,7 @@ one is included in the list below.
30733085
* `--conditions`, `-C`
30743086
* `--diagnostic-dir`
30753087
* `--disable-proto`
3088+
* `--disable-sigusr1`
30763089
* `--disable-warning`
30773090
* `--disable-wasm-trap-handler`
30783091
* `--dns-result-order`
@@ -3651,6 +3664,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
36513664
[`--build-snapshot`]: #--build-snapshot
36523665
[`--cpu-prof-dir`]: #--cpu-prof-dir
36533666
[`--diagnostic-dir`]: #--diagnostic-dirdirectory
3667+
[`--disable-sigusr1`]: #--disable-sigusr1
36543668
[`--env-file-if-exists`]: #--env-file-if-existsconfig
36553669
[`--env-file`]: #--env-fileconfig
36563670
[`--experimental-addon-modules`]: #--experimental-addon-modules

src/env-inl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,8 @@ inline bool Environment::no_global_search_paths() const {
666666
}
667667

668668
inline bool Environment::should_start_debug_signal_handler() const {
669-
return (flags_ & EnvironmentFlags::kNoStartDebugSignalHandler) == 0;
669+
return ((flags_ & EnvironmentFlags::kNoStartDebugSignalHandler) == 0) &&
670+
!options_->disable_sigusr1;
670671
}
671672

672673
inline bool Environment::no_browser_globals() const {

src/node_options.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
386386
" (default: current working directory)",
387387
&EnvironmentOptions::diagnostic_dir,
388388
kAllowedInEnvvar);
389+
AddOption("--disable-sigusr1",
390+
"Disable inspector thread to be listening for SIGUSR1 signal",
391+
&EnvironmentOptions::disable_sigusr1,
392+
kAllowedInEnvvar,
393+
false);
389394
AddOption("--dns-result-order",
390395
"set default value of verbatim in dns.lookup. Options are "
391396
"'ipv4first' (IPv4 addresses are placed before IPv6 addresses) "

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class EnvironmentOptions : public Options {
116116
bool abort_on_uncaught_exception = false;
117117
std::vector<std::string> conditions;
118118
bool detect_module = true;
119+
bool disable_sigusr1 = false;
119120
bool print_required_tla = false;
120121
bool require_module = true;
121122
std::string dns_result_order;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
console.log('pid is', process.pid);
2+
setInterval(() => {}, 1000);

test/parallel/test-disable-sigusr1.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fixtures = require('../common/fixtures');
5+
const { it } = require('node:test');
6+
const assert = require('node:assert');
7+
const { NodeInstance } = require('../common/inspector-helper.js');
8+
9+
common.skipIfInspectorDisabled();
10+
11+
it('should not attach a debugger with SIGUSR1', { skip: common.isWindows() }, async () => {
12+
const file = fixtures.path('disable-signal/sigusr1.js');
13+
const instance = new NodeInstance(['--disable-sigusr1'], undefined, file);
14+
15+
instance.on('stderr', common.mustNotCall());
16+
const loggedPid = await new Promise((resolve) => {
17+
instance.on('stdout', (data) => {
18+
const matches = data.match(/pid is (\d+)/);
19+
if (matches) resolve(Number(matches[1]));
20+
});
21+
});
22+
23+
assert.ok(process.kill(instance.pid, 'SIGUSR1'));
24+
assert.strictEqual(loggedPid, instance.pid);
25+
assert.ok(await instance.kill());
26+
});

0 commit comments

Comments
 (0)