Skip to content

Commit 94d3fe1

Browse files
RafaelGSSaduh95
authored andcommitted
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. PR-URL: #56441 Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7d1676e commit 94d3fe1

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

doc/api/cli.md

+14
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,17 @@ Disable the `Object.prototype.__proto__` property. If `mode` is `delete`, the
566566
property is removed entirely. If `mode` is `throw`, accesses to the
567567
property throw an exception with the code `ERR_PROTO_ACCESS`.
568568

569+
### `--disable-sigusr1`
570+
571+
<!-- YAML
572+
added: REPLACEME
573+
-->
574+
575+
> Stability: 1.2 - Release candidate
576+
577+
Disable the ability of starting a debugging session by sending a
578+
`SIGUSR1` signal to the process.
579+
569580
### `--disable-warning=code-or-type`
570581

571582
> Stability: 1.1 - Active development
@@ -1446,6 +1457,7 @@ added: v7.6.0
14461457

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

14501462
Default host is `127.0.0.1`. If port `0` is specified,
14511463
a random available port will be used.
@@ -3085,6 +3097,7 @@ one is included in the list below.
30853097
* `--conditions`, `-C`
30863098
* `--diagnostic-dir`
30873099
* `--disable-proto`
3100+
* `--disable-sigusr1`
30883101
* `--disable-warning`
30893102
* `--disable-wasm-trap-handler`
30903103
* `--dns-result-order`
@@ -3670,6 +3683,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
36703683
[`--build-snapshot`]: #--build-snapshot
36713684
[`--cpu-prof-dir`]: #--cpu-prof-dir
36723685
[`--diagnostic-dir`]: #--diagnostic-dirdirectory
3686+
[`--disable-sigusr1`]: #--disable-sigusr1
36733687
[`--env-file-if-exists`]: #--env-file-if-existsconfig
36743688
[`--env-file`]: #--env-fileconfig
36753689
[`--experimental-default-type=module`]: #--experimental-default-typetype

src/env-inl.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,8 @@ inline bool Environment::no_global_search_paths() const {
691691
}
692692

693693
inline bool Environment::should_start_debug_signal_handler() const {
694-
return (flags_ & EnvironmentFlags::kNoStartDebugSignalHandler) == 0;
694+
return ((flags_ & EnvironmentFlags::kNoStartDebugSignalHandler) == 0) &&
695+
!options_->disable_sigusr1;
695696
}
696697

697698
inline bool Environment::no_browser_globals() const {

src/node_options.cc

+5
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
389389
" (default: current working directory)",
390390
&EnvironmentOptions::diagnostic_dir,
391391
kAllowedInEnvvar);
392+
AddOption("--disable-sigusr1",
393+
"Disable inspector thread to be listening for SIGUSR1 signal",
394+
&EnvironmentOptions::disable_sigusr1,
395+
kAllowedInEnvvar,
396+
false);
392397
AddOption("--dns-result-order",
393398
"set default value of verbatim in dns.lookup. Options are "
394399
"'ipv4first' (IPv4 addresses are placed before IPv6 addresses) "

src/node_options.h

+1
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;
+2
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

+26
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)