Skip to content
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 17 commits into from Nov 29, 2022

Conversation

deepak1556
Copy link
Member

@deepak1556 deepak1556 commented Nov 28, 2022

Description of Change

Fixes #36030

Co-authored by: @VerteDinde , @nornagon

Release Notes

Notes: Enable crashpad for ELECTRON_RUN_AS_NODE processes.

@deepak1556 deepak1556 requested a review from a team as a code owner November 28, 2022 11:23
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Nov 28, 2022
@deepak1556 deepak1556 added target/22-x-y PR should also be added to the "22-x-y" branch. semver/patch backwards-compatible bug fixes labels Nov 28, 2022
@deepak1556 deepak1556 changed the title fix: enable crashpad for processes created with child_process.fork fix: enable crashpad for ELECTRON_RUN_AS_NODE processes Nov 28, 2022
patches/node/enable_crashpad_linux_node_processes.patch Outdated Show resolved Hide resolved
patches/node/enable_crashpad_linux_node_processes.patch Outdated Show resolved Hide resolved
patches/node/enable_crashpad_linux_node_processes.patch Outdated Show resolved Hide resolved
shell/app/node_main.cc Outdated Show resolved Hide resolved
shell/app/node_main.cc Outdated Show resolved Hide resolved
shell/app/node_main.cc Outdated Show resolved Hide resolved
shell/app/node_main.cc Outdated Show resolved Hide resolved
Comment on lines 43 to 44
+ 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;
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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 🙇‍♀️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ecd98e8

Copy link
Member

Choose a reason for hiding this comment

The 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.

shell/app/node_main.cc Outdated Show resolved Hide resolved
shell/app/node_main.cc Outdated Show resolved Hide resolved
@@ -27,13 +27,14 @@ index 73c1dc769542865bdf7a2a03c16cef141d3f4b05..35a096dcff6f7072391bccd7952da7e8
args = [...execArgv, modulePath, ...args];

if (typeof options.stdio === 'string') {
@@ -613,6 +613,21 @@ function normalizeSpawnArguments(file, args, options) {
@@ -613,6 +613,22 @@ function normalizeSpawnArguments(file, args, options) {
'options.windowsVerbatimArguments');
}

+ if (process.platform === 'linux') {
+ if (ObjectPrototypeHasOwnProperty(options.env || {}, 'ELECTRON_RUN_AS_NODE') &&
Copy link
Member

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?

Copy link
Member

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

Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test needs a little work!

spec/api-crash-reporter-spec.ts Outdated Show resolved Hide resolved
spec/fixtures/apps/crash/node-extra-args.js Outdated Show resolved Hide resolved
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Nov 29, 2022
}

+ if (process.platform === 'linux') {
+ if (ObjectPrototypeHasOwnProperty(options.env || process.env, 'ELECTRON_RUN_AS_NODE') &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking on it, but what's the path forward for this patch? Is it something we're anticipating floating for the long-term?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there’s two approaches we could take in the long-term:

  1. Move this functionality out of our forked child_process.fork and into the new UtilityProcess API. If we did that, we could likely remove this patch, but I think the API needs additional feature work before that can be done.
  2. This becomes a long-running patch similar to our implementation of Breakpad in Node (see b10f243 )

I think the immediate plan is #2, but we’re looking at if #1 is feasible

@VerteDinde VerteDinde removed their request for review November 29, 2022 15:06
@jkleinsc jkleinsc merged commit 2c723d7 into main Nov 29, 2022
@jkleinsc jkleinsc deleted the enable-crashpad-node-processes branch November 29, 2022 15:33
@release-clerk
Copy link

release-clerk bot commented Nov 29, 2022

Release Notes Persisted

Enable crashpad for ELECTRON_RUN_AS_NODE processes.

@trop
Copy link
Contributor

trop bot commented Nov 29, 2022

I was unable to backport this PR to "22-x-y" cleanly;
you will need to perform this backport manually.

@trop trop bot added needs-manual-bp/22-x-y and removed target/22-x-y PR should also be added to the "22-x-y" branch. labels Nov 29, 2022
@trop
Copy link
Contributor

trop bot commented Nov 29, 2022

@VerteDinde has manually backported this PR to "22-x-y", please check out #36483

@trop trop bot added in-flight/22-x-y merged/22-x-y PR was merged to the "22-x-y" branch. and removed needs-manual-bp/22-x-y in-flight/22-x-y labels Nov 29, 2022
khalwa pushed a commit to solarwindscloud/electron that referenced this pull request Feb 22, 2023
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged/22-x-y PR was merged to the "22-x-y" branch. semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable crashpad support on linux for ELECTRON_RUN_AS_NODE processes
5 participants