-
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a177d0d
wip: enable crashpad for node processes
VerteDinde 5d263b0
node::ProcessInitializationFlags::kNoDefaultSignalHandling
nornagon bae57a8
chore: clean up debug logging
VerteDinde 2626021
chore: gate platform includes
VerteDinde 530fdfb
test: clean up node process test
VerteDinde ad4f0d4
fix: pass pid in node_main
VerteDinde 49e1519
chore: cleanup impl
deepak1556 cd77422
chore: fixup patch method definition
VerteDinde ac8b23f
fix: expose bound methods to node_main
VerteDinde f644a62
fix: remove bound methods
VerteDinde d00181c
fix: crashpad connection for all ELECTRON_RUN_AS_NODE processes
deepak1556 1665dd5
chore: fix typo
deepak1556 21b0e1f
chore: address review feedback
deepak1556 be15662
chore: delay crashpad initialization
deepak1556 ecd98e8
chore: ensure options.env, code hygiene
VerteDinde 9463804
chore: add argv test, check for process.env over {}
VerteDinde d0e268c
fix: fix test, return options.env immutability
VerteDinde File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: VerteDinde <keeleymhammond@gmail.com> | ||
Date: Sun, 20 Nov 2022 21:45:20 -0800 | ||
Subject: fix: enable crashpad for ELECTRON_RUN_AS_NODE linux processes | ||
|
||
Passes the crashpad handler PID and crashdump signal file descriptor | ||
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..35a096dcff6f7072391bccd7952da7e8ea8980bb 100644 | ||
--- a/lib/child_process.js | ||
+++ b/lib/child_process.js | ||
@@ -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 +613,21 @@ function normalizeSpawnArguments(file, args, options) { | ||
'options.windowsVerbatimArguments'); | ||
} | ||
|
||
+ if (process.platform === 'linux') { | ||
+ if (ObjectPrototypeHasOwnProperty(options.env || {}, 'ELECTRON_RUN_AS_NODE') && | ||
+ (file === process.execPath)) { | ||
deepak1556 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
+ // 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; | ||
+ options.env.CRASHPAD_HANDLER_PID = pid; | ||
+ } | ||
+ } | ||
+ } | ||
+ | ||
if (options.shell) { | ||
const command = ArrayPrototypeJoin([file, ...args], ' '); | ||
// Set the shell, switches, and commands. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2022 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "shell/common/gin_helper/dictionary.h" | ||
#include "shell/common/node_includes.h" | ||
|
||
#if BUILDFLAG(IS_LINUX) | ||
#include "components/crash/core/app/crashpad.h" // nogncheck | ||
#endif | ||
|
||
namespace { | ||
|
||
#if BUILDFLAG(IS_LINUX) | ||
int GetCrashdumpSignalFD() { | ||
int fd; | ||
return crash_reporter::GetHandlerSocket(&fd, nullptr) ? fd : -1; | ||
} | ||
|
||
int GetCrashpadHandlerPID() { | ||
int pid; | ||
return crash_reporter::GetHandlerSocket(nullptr, &pid) ? pid : -1; | ||
} | ||
#endif | ||
|
||
void Initialize(v8::Local<v8::Object> exports, | ||
v8::Local<v8::Value> unused, | ||
v8::Local<v8::Context> context, | ||
void* priv) { | ||
gin_helper::Dictionary dict(context->GetIsolate(), exports); | ||
#if BUILDFLAG(IS_LINUX) | ||
dict.SetMethod("getCrashdumpSignalFD", &GetCrashdumpSignalFD); | ||
dict.SetMethod("getCrashpadHandlerPID", &GetCrashpadHandlerPID); | ||
#endif | ||
} | ||
|
||
} // namespace | ||
|
||
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_common_crashpad_support, Initialize) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const path = require('path'); | ||
const childProcess = require('child_process'); | ||
|
||
const crashPath = path.join(__dirname, 'node-crash.js'); | ||
const child = childProcess.fork(crashPath, { silent: true }); | ||
child.on('exit', () => process.exit(0)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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