Skip to content

Commit c35f3ea

Browse files
HarshithaKPtargos
authored andcommitted
report: handle on-fatalerror better
--report-on-fatalerror was not honored properly, as there was no way to check the value which was stored in the Environment pointer which can be inaccessible under certain fatal error situations. Move the flag out of Environment pointer so that this is doable. Co-authored-by: Shobhit Chittora [email protected] PR-URL: nodejs#32207 Fixes: nodejs#31576 Refs: nodejs#29881 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Sam Roberts <[email protected]>
1 parent be92b25 commit c35f3ea

5 files changed

+31
-22
lines changed

src/node_errors.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ void OnFatalError(const char* location, const char* message) {
406406

407407
Isolate* isolate = Isolate::GetCurrent();
408408
Environment* env = Environment::GetCurrent(isolate);
409-
if (env == nullptr || env->isolate_data()->options()->report_on_fatalerror) {
409+
if (per_process::cli_options->report_on_fatalerror) {
410410
report::TriggerNodeReport(
411411
isolate, env, message, "FatalError", "", Local<String>());
412412
}

src/node_options.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -599,10 +599,6 @@ PerIsolateOptionsParser::PerIsolateOptionsParser(
599599
"generate diagnostic report upon receiving signals",
600600
&PerIsolateOptions::report_on_signal,
601601
kAllowedInEnvironment);
602-
AddOption("--report-on-fatalerror",
603-
"generate diagnostic report on fatal (internal) errors",
604-
&PerIsolateOptions::report_on_fatalerror,
605-
kAllowedInEnvironment);
606602
AddOption("--report-signal",
607603
"causes diagnostic report to be produced on provided signal,"
608604
" unsupported in Windows. (default: SIGUSR2)",
@@ -680,6 +676,10 @@ PerProcessOptionsParser::PerProcessOptionsParser(
680676
AddOption("--v8-options",
681677
"print V8 command line options",
682678
&PerProcessOptions::print_v8_help);
679+
AddOption("--report-on-fatalerror",
680+
"generate diagnostic report on fatal (internal) errors",
681+
&PerProcessOptions::report_on_fatalerror,
682+
kAllowedInEnvironment);
683683

684684
#ifdef NODE_HAVE_I18N_SUPPORT
685685
AddOption("--icu-data-dir",

src/node_options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ class PerIsolateOptions : public Options {
187187
bool no_node_snapshot = false;
188188
bool report_uncaught_exception = false;
189189
bool report_on_signal = false;
190-
bool report_on_fatalerror = false;
191190
bool report_compact = false;
192191
std::string report_signal = "SIGUSR2";
193192
std::string report_filename;
@@ -238,6 +237,7 @@ class PerProcessOptions : public Options {
238237
std::string use_largepages = "off";
239238
bool trace_sigint = false;
240239
std::vector<std::string> cmdline;
240+
bool report_on_fatalerror = false;
241241

242242
inline PerIsolateOptions* get_per_isolate_options();
243243
void CheckOptions(std::vector<std::string>* errors) override;

src/node_report_module.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ static void SetSignal(const FunctionCallbackInfo<Value>& info) {
131131
static void ShouldReportOnFatalError(const FunctionCallbackInfo<Value>& info) {
132132
Environment* env = Environment::GetCurrent(info);
133133
info.GetReturnValue().Set(
134-
env->isolate_data()->options()->report_on_fatalerror);
134+
node::per_process::cli_options->report_on_fatalerror);
135135
}
136136

137137
static void SetReportOnFatalError(const FunctionCallbackInfo<Value>& info) {
138138
Environment* env = Environment::GetCurrent(info);
139139
CHECK(info[0]->IsBoolean());
140-
env->isolate_data()->options()->report_on_fatalerror = info[0]->IsTrue();
140+
node::per_process::cli_options->report_on_fatalerror = info[0]->IsTrue();
141141
}
142142

143143
static void ShouldReportOnSignal(const FunctionCallbackInfo<Value>& info) {
+23-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const common = require('../common');
3+
require('../common');
44
const assert = require('assert');
55
// Testcase to produce report on fatal error (javascript heap OOM)
66
if (process.argv[2] === 'child') {
@@ -20,17 +20,26 @@ if (process.argv[2] === 'child') {
2020
const helper = require('../common/report.js');
2121
const tmpdir = require('../common/tmpdir');
2222
tmpdir.refresh();
23-
const spawn = require('child_process').spawn;
24-
const args = ['--report-on-fatalerror',
25-
'--max-old-space-size=20',
26-
__filename,
27-
'child'];
28-
const child = spawn(process.execPath, args, { cwd: tmpdir.path });
29-
child.on('exit', common.mustCall((code) => {
30-
assert.notStrictEqual(code, 0, 'Process exited unexpectedly');
31-
const reports = helper.findReports(child.pid, tmpdir.path);
32-
assert.strictEqual(reports.length, 1);
33-
const report = reports[0];
34-
helper.validate(report);
35-
}));
23+
const spawnSync = require('child_process').spawnSync;
24+
let args = ['--report-on-fatalerror',
25+
'--max-old-space-size=20',
26+
__filename,
27+
'child'];
28+
29+
let child = spawnSync(process.execPath, args, { cwd: tmpdir.path });
30+
31+
assert.notStrictEqual(child.status, 0, 'Process exited unexpectedly');
32+
let reports = helper.findReports(child.pid, tmpdir.path);
33+
assert.strictEqual(reports.length, 1);
34+
const report = reports[0];
35+
helper.validate(report);
36+
// Verify that reports are not created on fatal error by default.
37+
args = ['--max-old-space-size=20',
38+
__filename,
39+
'child'];
40+
41+
child = spawnSync(process.execPath, args, { cwd: tmpdir.path });
42+
assert.notStrictEqual(child.status, 0, 'Process exited unexpectedly');
43+
reports = helper.findReports(child.pid, tmpdir.path);
44+
assert.strictEqual(reports.length, 0);
3645
}

0 commit comments

Comments
 (0)