Skip to content

Commit

Permalink
fix: fix test, return options.env immutability
Browse files Browse the repository at this point in the history
  • Loading branch information
VerteDinde committed Nov 29, 2022
1 parent 9463804 commit 9d3bedb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 33 deletions.
22 changes: 3 additions & 19 deletions patches/node/enable_crashpad_linux_node_processes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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..a77e75c0893378021c9289185e6dd9facc064e39 100644
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(
Expand All @@ -27,28 +27,12 @@ index 73c1dc769542865bdf7a2a03c16cef141d3f4b05..a77e75c0893378021c9289185e6dd9fa
args = [...execArgv, modulePath, ...args];

if (typeof options.stdio === 'string') {
@@ -561,10 +561,12 @@ function normalizeSpawnArguments(file, args, options) {
args = [];
}

- if (options === undefined)
- options = kEmptyObject;
- else
+ if (options === undefined) {
+ options = Object.create(null);
+ options.env = Object.create(null);
+ } else {
validateObject(options, 'options');
+ }

let cwd = options.cwd;

@@ -613,6 +615,21 @@ function normalizeSpawnArguments(file, args, options) {
@@ -613,6 +613,21 @@ function normalizeSpawnArguments(file, args, options) {
'options.windowsVerbatimArguments');
}

+ if (process.platform === 'linux') {
+ if (ObjectPrototypeHasOwnProperty(options.env || process.env, 'ELECTRON_RUN_AS_NODE') &&
+ if (ObjectPrototypeHasOwnProperty(options.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.
Expand Down
17 changes: 12 additions & 5 deletions spec/api-crash-reporter-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,18 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_

ifit(!isLinuxOnArm)('ensure child process args are not modified', async () => {
const { port, waitForCrash } = await startServer();
runCrashApp('node-extra-args', port);
const crash = await waitForCrash();
checkCrash('node', crash);
expect(crash.mainProcessSpecific).to.be.undefined();
expect(crash.rendererSpecific).to.be.undefined();
let exitCode: number | null = null;
const appPath = path.join(__dirname, 'fixtures', 'apps', 'crash');
const crashType = 'node-extra-args';
const crashProcess = childProcess.spawn(process.execPath, [appPath,
`--crash-type=${crashType}`,
`--crash-reporter-url=http://127.0.0.1:${port}`
], { stdio: 'inherit' });
crashProcess.once('close', (code) => {
exitCode = code;
});
await waitForCrash();
expect(exitCode).to.equal(0);
});

describe('with guid', () => {
Expand Down
7 changes: 6 additions & 1 deletion spec/fixtures/apps/crash/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@ app.whenReady().then(() => {
const child = childProcess.fork(scriptPath, { silent: true });
child.on('exit', () => process.exit(0));
} else if (crashType === 'node-extra-args') {
let exitcode = -1;
const crashPath = path.join(__dirname, 'node-extra-args.js');
const child = childProcess.fork(crashPath, ['--enable-logging'], { silent: true });
child.on('exit', () => process.exit(0));
child.send('message');
child.on('message', (forkedArgs) => {
if (JSON.stringify(forkedArgs) !== JSON.stringify(child.spawnargs)) { exitcode = 1; } else { exitcode = 0; }
process.exit(exitcode);
});
} else {
console.error(`Unrecognized crash type: '${crashType}'`);
process.exit(1);
Expand Down
15 changes: 7 additions & 8 deletions spec/fixtures/apps/crash/node-extra-args.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const path = require('path');
const childProcess = require('child_process');
const argv = process.argv;
let exitCode = 0;
if (argv.length !== 3) {
exitCode = 1;
}
const crashPath = path.join(__dirname, 'node-crash.js');
const child = childProcess.fork(crashPath, { silent: true });
child.on('exit', () => process.exit(exitCode));

process.on('message', function () {
process.send(process.argv);
});

// Allow time to send args, then crash the app.
setTimeout(() => process.nextTick(() => process.crash()), 10000);

0 comments on commit 9d3bedb

Please sign in to comment.