-
Notifications
You must be signed in to change notification settings - Fork 15k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: enable crashpad for ELECTRON_RUN_AS_NODE processes #36460
Changes from 3 commits
a177d0d
5d263b0
bae57a8
2626021
530fdfb
ad4f0d4
49e1519
cd77422
ac8b23f
f644a62
d00181c
1665dd5
21b0e1f
be15662
ecd98e8
9463804
d0e268c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,53 +8,44 @@ to child processes spawned with `ELECTRON_RUN_AS_NODE` which is used | |
by the crashpad client to connect with the handler process. | ||
|
||
diff --git a/lib/child_process.js b/lib/child_process.js | ||
index 73c1dc769542865bdf7a2a03c16cef141d3f4b05..4c725a991b803c2bfde58b674df15b328102450b 100644 | ||
index 73c1dc769542865bdf7a2a03c16cef141d3f4b05..35a096dcff6f7072391bccd7952da7e8ea8980bb 100644 | ||
--- a/lib/child_process.js | ||
+++ b/lib/child_process.js | ||
@@ -159,7 +159,6 @@ function fork(modulePath, args = [], options) { | ||
@@ -59,6 +59,7 @@ let debug = require('internal/util/debuglog').debuglog( | ||
); | ||
const { Buffer } = require('buffer'); | ||
const { Pipe, constants: PipeConstants } = internalBinding('pipe_wrap'); | ||
+const { getCrashdumpSignalFD, getCrashpadHandlerPID } = process._linkedBinding('electron_common_crashpad_support'); | ||
|
||
const { | ||
AbortError, | ||
@@ -159,7 +160,6 @@ function fork(modulePath, args = [], options) { | ||
ArrayPrototypeSplice(execArgv, index - 1, 2); | ||
} | ||
} | ||
- | ||
args = [...execArgv, modulePath, ...args]; | ||
|
||
if (typeof options.stdio === 'string') { | ||
@@ -613,6 +612,22 @@ function normalizeSpawnArguments(file, args, options) { | ||
@@ -613,6 +613,21 @@ function normalizeSpawnArguments(file, args, options) { | ||
'options.windowsVerbatimArguments'); | ||
} | ||
|
||
+ if (process.platform === 'linux') { | ||
+ if (ObjectPrototypeHasOwnProperty(options.env || {}, 'ELECTRON_RUN_AS_NODE') && | ||
+ (file === process.execPath)) { | ||
+ // On Linux, pass the file descriptor which crashpad server process | ||
+ // uses to monitor the child process. | ||
+ const fd = process.getCrashdumpSignalFD(); | ||
+ if (fd !== -1) { | ||
+ // On Linux, pass the file descriptor which crashpad handler process | ||
+ // uses to monitor the child process and PID of the handler process. | ||
+ // https://source.chromium.org/chromium/chromium/src/+/110.0.5415.0:components/crash/core/app/crashpad_linux.cc;l=199-206 | ||
+ const fd = getCrashdumpSignalFD(); | ||
+ const pid = getCrashpadHandlerPID(); | ||
+ if (fd !== -1 && pid !== -1) { | ||
+ options.env.CRASHDUMP_SIGNAL_FD = fd; | ||
+ // On Linux, pass the PID of the crashpad handler process to the child process | ||
+ // which is needed by the crashpad client running in the child process. | ||
+ // https://source.chromium.org/chromium/chromium/src/+/110.0.5415.0:components/crash/core/app/crashpad_linux.cc;l=199-206 | ||
+ ArrayPrototypePush(args, `--crashpad-handler-pid=${process.getCrashpadHandlerPID()}`); | ||
+ options.env.CRASHPAD_HANDLER_PID = pid; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if options / options.env can be null, do we need to make sure we initialize those as objects here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think that's a good callout, I'll add that in 🙇♀️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in ecd98e8 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a heads up, I reverted initializing options.env here in d0e268c after seeing multiple node test failures. It looks like node expects the options object to not be extendable here, so we can't create an options.env at this point if it doesn't already exist. We can add properties to options.env if it exists though, which our check should gate for. |
||
+ } | ||
+ } | ||
+ } | ||
+ | ||
if (options.shell) { | ||
const command = ArrayPrototypeJoin([file, ...args], ' '); | ||
// Set the shell, switches, and commands. | ||
diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js | ||
index 6659f03e9aa45c35d355399597f533ad20232575..c1460d9f12607ecb26b602a15a516f013047f57d 100644 | ||
--- a/lib/internal/process/pre_execution.js | ||
+++ b/lib/internal/process/pre_execution.js | ||
@@ -59,6 +59,11 @@ function prepareMainThreadExecution(expandArgv1 = false, | ||
setupCoverageHooks(process.env.NODE_V8_COVERAGE); | ||
} | ||
|
||
+ if (process.env.CRASHDUMP_SIGNAL_FD) { | ||
+ // Make sure it's not accidentally inherited by child processes. | ||
+ delete process.env.CRASHDUMP_SIGNAL_FD; | ||
+ } | ||
+ | ||
setupDebugEnv(); | ||
|
||
// Print stack trace on `SIGINT` if option `--trace-sigint` presents. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since options.env isn't necessarily set here, how does this work...? should this be
options.env || process.env
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, I think so? Made the change in 9463804