Skip to content

Commit 0f094cb

Browse files
report: add --report-disable-network option
New option `--report-disable-network`, also available as `report.disableNetwork`, enables the user to disable networking interfaces in their diagnostic report. On some systems, this can cause the report to take minutes to generate so this option can be used to optimize that. fixes: #46060
1 parent 68885d5 commit 0f094cb

File tree

6 files changed

+64
-5
lines changed

6 files changed

+64
-5
lines changed

lib/internal/process/report.js

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ const report = {
6060
validateBoolean(b, 'compact');
6161
nr.setCompact(b);
6262
},
63+
get disableNetwork() {
64+
return nr.getDisableNetwork();
65+
},
66+
set disableNetwork(b) {
67+
validateBoolean(b, 'disableNetwork');
68+
nr.setDisableNetwork(b);
69+
},
6370
get signal() {
6471
return nr.getSignal();
6572
},

src/node_options.cc

+5
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,11 @@ PerProcessOptionsParser::PerProcessOptionsParser(
950950
"generate diagnostic report on fatal (internal) errors",
951951
&PerProcessOptions::report_on_fatalerror,
952952
kAllowedInEnvvar);
953+
AddOption("--report-disable-network",
954+
"disable network interface diagnostics."
955+
" (default: false)",
956+
&PerProcessOptions::report_disable_network,
957+
kAllowedInEnvvar);
953958

954959
#ifdef NODE_HAVE_I18N_SUPPORT
955960
AddOption("--icu-data-dir",

src/node_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ class PerProcessOptions : public Options {
306306
bool report_compact = false;
307307
std::string report_directory;
308308
std::string report_filename;
309+
bool report_disable_network = false;
309310

310311
// TODO(addaleax): Some of these could probably be per-Environment.
311312
std::string use_largepages = "off";

src/node_report.cc

+23-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ static void WriteNodeReport(Isolate* isolate,
6161
const std::string& filename,
6262
std::ostream& out,
6363
Local<Value> error,
64-
bool compact);
64+
bool compact,
65+
bool disable_network);
6566
static void PrintVersionInformation(JSONWriter* writer);
6667
static void PrintJavaScriptErrorStack(JSONWriter* writer,
6768
Isolate* isolate,
@@ -93,7 +94,8 @@ static void WriteNodeReport(Isolate* isolate,
9394
const std::string& filename,
9495
std::ostream& out,
9596
Local<Value> error,
96-
bool compact) {
97+
bool compact,
98+
bool disable_network) {
9799
// Obtain the current time and the pid.
98100
TIME_TYPE tm_struct;
99101
DiagnosticFilename::LocalTime(&tm_struct);
@@ -917,8 +919,14 @@ std::string TriggerNodeReport(Isolate* isolate,
917919
compact = per_process::cli_options->report_compact;
918920
}
919921

922+
bool disable_network;
923+
{
924+
Mutex::ScopedLock lock(per_process::cli_options_mutex);
925+
disable_network = per_process::cli_options->report_disable_network;
926+
}
927+
920928
report::WriteNodeReport(
921-
isolate, env, message, trigger, filename, *outstream, error, compact);
929+
isolate, env, message, trigger, filename, *outstream, error, compact, disable_network);
922930

923931
// Do not close stdout/stderr, only close files we opened.
924932
if (outfile.is_open()) {
@@ -969,8 +977,13 @@ void GetNodeReport(Isolate* isolate,
969977
if (isolate != nullptr) {
970978
env = Environment::GetCurrent(isolate);
971979
}
980+
bool disable_network;
981+
{
982+
Mutex::ScopedLock lock(per_process::cli_options_mutex);
983+
disable_network = per_process::cli_options->report_disable_network;
984+
}
972985
report::WriteNodeReport(
973-
isolate, env, message, trigger, "", out, error, false);
986+
isolate, env, message, trigger, "", out, error, false, disable_network);
974987
}
975988

976989
// External function to trigger a report, writing to a supplied stream.
@@ -983,8 +996,13 @@ void GetNodeReport(Environment* env,
983996
if (env != nullptr) {
984997
isolate = env->isolate();
985998
}
999+
bool disable_network;
1000+
{
1001+
Mutex::ScopedLock lock(per_process::cli_options_mutex);
1002+
disable_network = per_process::cli_options->report_disable_network;
1003+
}
9861004
report::WriteNodeReport(
987-
isolate, env, message, trigger, "", out, error, false);
1005+
isolate, env, message, trigger, "", out, error, false, disable_network);
9881006
}
9891007

9901008
} // namespace node

src/node_report_module.cc

+17
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ static void SetCompact(const FunctionCallbackInfo<Value>& info) {
8484
per_process::cli_options->report_compact = compact;
8585
}
8686

87+
static void GetDisableNetwork(const FunctionCallbackInfo<Value>& info) {
88+
Mutex::ScopedLock lock(per_process::cli_options_mutex);
89+
info.GetReturnValue().Set(per_process::cli_options->report_disable_network);
90+
}
91+
92+
static void SetDisableNetwork(const FunctionCallbackInfo<Value>& info) {
93+
Mutex::ScopedLock lock(per_process::cli_options_mutex);
94+
Environment* env = Environment::GetCurrent(info);
95+
Isolate* isolate = env->isolate();
96+
bool disable_network = info[0]->ToBoolean(isolate)->Value();
97+
per_process::cli_options->report_disable_network = disable_network;
98+
}
99+
87100
static void GetDirectory(const FunctionCallbackInfo<Value>& info) {
88101
Mutex::ScopedLock lock(per_process::cli_options_mutex);
89102
Environment* env = Environment::GetCurrent(info);
@@ -174,6 +187,8 @@ static void Initialize(Local<Object> exports,
174187
SetMethod(context, exports, "getReport", GetReport);
175188
SetMethod(context, exports, "getCompact", GetCompact);
176189
SetMethod(context, exports, "setCompact", SetCompact);
190+
SetMethod(context, exports, "getDisableNetwork", GetDisableNetwork);
191+
SetMethod(context, exports, "setDisableNetwork", SetDisableNetwork);
177192
SetMethod(context, exports, "getDirectory", GetDirectory);
178193
SetMethod(context, exports, "setDirectory", SetDirectory);
179194
SetMethod(context, exports, "getFilename", GetFilename);
@@ -200,6 +215,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
200215
registry->Register(GetReport);
201216
registry->Register(GetCompact);
202217
registry->Register(SetCompact);
218+
registry->Register(GetDisableNetwork);
219+
registry->Register(SetDisableNetwork);
203220
registry->Register(GetDirectory);
204221
registry->Register(SetDirectory);
205222
registry->Register(GetFilename);

test/report/test-report-config.js

+11
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ assert.throws(() => {
6666
}, { code: 'ERR_INVALID_ARG_TYPE' });
6767
assert.strictEqual(process.report.compact, true);
6868

69+
// Verify that process.report.reportDisableNetwork behaves properly.
70+
assert.strictEqual(process.report.disableNetwork, true);
71+
process.report.disableNetwork = false;
72+
assert.strictEqual(process.report.disableNetwork, false);
73+
process.report.disableNetwork = true;
74+
assert.strictEqual(process.report.disableNetwork, true);
75+
assert.throws(() => {
76+
process.report.disableNetwork = {};
77+
}, { code: 'ERR_INVALID_ARG_TYPE' });
78+
assert.strictEqual(process.report.disableNetwork, true);
79+
6980
if (!common.isWindows) {
7081
// Verify that process.report.signal behaves properly.
7182
assert.strictEqual(process.report.signal, 'SIGUSR2');

0 commit comments

Comments
 (0)