Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: enable crashpad for ELECTRON_RUN_AS_NODE processes (#36483)
* fix: enable crashpad for ELECTRON_RUN_AS_NODE processes * wip: enable crashpad for node processes fix: add PID testing method wip: plumb fd into child_process in node * node::ProcessInitializationFlags::kNoDefaultSignalHandling * chore: clean up debug logging * chore: gate platform includes * test: clean up node process test * fix: pass pid in node_main * chore: cleanup impl * chore: fixup patch method definition * fix: expose bound methods to node_main * fix: remove bound methods * fix: crashpad connection for all ELECTRON_RUN_AS_NODE processes * chore: fix typo * chore: address review feedback * chore: delay crashpad initialization * chore: ensure options.env, code hygiene * chore: add argv test, check for process.env over {} * fix: fix test, return options.env immutability Co-authored-by: VerteDinde <keeleymhammond@gmail.com> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: VerteDinde <vertedinde@electronjs.org> * chore: update patches Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
- Loading branch information
1 parent
e879e2f
commit 8d9a964
Showing
10 changed files
with
194 additions
and
12 deletions.
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 2a91c4820bebf55068c4d54a2e1133176de77a6d..a9eb36881acb8eba50f05758995ebe327de86a2d 100644 | ||
--- a/lib/child_process.js | ||
+++ b/lib/child_process.js | ||
@@ -58,6 +58,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, | ||
@@ -146,7 +147,6 @@ function fork(modulePath, args = [], options) { | ||
ArrayPrototypeSplice(execArgv, index - 1, 2); | ||
} | ||
} | ||
- | ||
args = [...execArgv, modulePath, ...args]; | ||
|
||
if (typeof options.stdio === 'string') { | ||
@@ -592,6 +592,21 @@ function normalizeSpawnArguments(file, args, options) { | ||
'options.windowsVerbatimArguments'); | ||
} | ||
|
||
+ if (process.platform === 'linux') { | ||
+ if (ObjectPrototypeHasOwnProperty(options.env || process.env, 'ELECTRON_RUN_AS_NODE') && | ||
+ (file === process.execPath)) { | ||
+ // 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
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,9 @@ | ||
const path = require('path'); | ||
const childProcess = require('child_process'); | ||
|
||
process.on('message', function () { | ||
process.send(process.argv); | ||
}); | ||
|
||
// Allow time to send args, then crash the app. | ||
setTimeout(() => process.nextTick(() => process.crash()), 10000); |