X Tutup
Skip to content

Commit 4e0e615

Browse files
lepinayzcbenz
authored andcommitted
fix: Expose missing Add/RemoveExtraParameter methods to macOS node child processes (electron#15790)
* Expose missing crash reporter methods in mac node processes * Crashpad migration
1 parent c9a455e commit 4e0e615

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

shell/app/node_main.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "shell/app/node_main.h"
66

77
#include <memory>
8+
#include <string>
89
#include <utility>
910

1011
#include "base/command_line.h"
@@ -31,6 +32,16 @@
3132

3233
namespace electron {
3334

35+
#if !defined(OS_LINUX)
36+
void AddExtraParameter(const std::string& key, const std::string& value) {
37+
crash_reporter::CrashReporter::GetInstance()->AddExtraParameter(key, value);
38+
}
39+
40+
void RemoveExtraParameter(const std::string& key) {
41+
crash_reporter::CrashReporter::GetInstance()->RemoveExtraParameter(key);
42+
}
43+
#endif
44+
3445
int NodeMain(int argc, char* argv[]) {
3546
base::CommandLine::Init(argc, argv);
3647

@@ -87,6 +98,12 @@ int NodeMain(int argc, char* argv[]) {
8798
// Setup process.crashReporter.start in child node processes
8899
auto reporter = mate::Dictionary::CreateEmpty(gin_env.isolate());
89100
reporter.SetMethod("start", &crash_reporter::CrashReporter::StartInstance);
101+
102+
#if !defined(OS_LINUX)
103+
reporter.SetMethod("addExtraParameter", &AddExtraParameter);
104+
reporter.SetMethod("removeExtraParameter", &RemoveExtraParameter);
105+
#endif
106+
90107
process.Set("crashReporter", reporter);
91108

92109
mate::Dictionary versions;

spec/api-crash-reporter-spec.js

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('crashReporter module', () => {
2323

2424
let originalTempDirectory = null
2525
let tempDirectory = null
26+
const specTimeout = 180000
2627

2728
before(() => {
2829
tempDirectory = temp.mkdirSync('electronCrashReporterSpec-')
@@ -56,7 +57,7 @@ describe('crashReporter module', () => {
5657
})
5758

5859
it('should send minidump when renderer crashes', function (done) {
59-
this.timeout(180000)
60+
this.timeout(specTimeout)
6061

6162
stopServer = startServer({
6263
callback (port) {
@@ -68,7 +69,7 @@ describe('crashReporter module', () => {
6869
})
6970

7071
it('should send minidump when node processes crash', function (done) {
71-
this.timeout(180000)
72+
this.timeout(specTimeout)
7273

7374
stopServer = startServer({
7475
callback (port) {
@@ -84,7 +85,7 @@ describe('crashReporter module', () => {
8485
})
8586

8687
it('should not send minidump if uploadToServer is false', function (done) {
87-
this.timeout(180000)
88+
this.timeout(specTimeout)
8889

8990
let dumpFile
9091
let crashesDir = crashReporter.getCrashesDirectory()
@@ -149,8 +150,46 @@ describe('crashReporter module', () => {
149150
})
150151
})
151152

153+
it('should send minidump with updated extra parameters when node processes crash', function (done) {
154+
if (process.platform === 'linux') {
155+
// FIXME(alexeykuzmin): Skip the test.
156+
// this.skip()
157+
return
158+
}
159+
// TODO(alexeykuzmin): Skip the test instead of marking it as passed.
160+
if (process.env.APPVEYOR === 'True') return done()
161+
this.timeout(specTimeout)
162+
stopServer = startServer({
163+
callback (port) {
164+
const crashesDir = path.join(app.getPath('temp'), `${process.platform === 'win32' ? 'Zombies' : app.getName()} Crashes`)
165+
const version = app.getVersion()
166+
const crashPath = path.join(fixtures, 'module', 'crash.js')
167+
if (process.platform === 'win32') {
168+
const crashServiceProcess = childProcess.spawn(process.execPath, [
169+
`--reporter-url=http://127.0.0.1:${port}`,
170+
'--application-name=Zombies',
171+
`--crashes-directory=${crashesDir}`
172+
], {
173+
env: {
174+
ELECTRON_INTERNAL_CRASH_SERVICE: 1
175+
},
176+
detached: true
177+
})
178+
remote.process.crashServicePid = crashServiceProcess.pid
179+
}
180+
childProcess.fork(crashPath, [port, version, crashesDir], { silent: true })
181+
},
182+
processType: 'browser',
183+
done: done,
184+
preAssert: fields => {
185+
expect(String(fields.newExtra)).to.equal('newExtra')
186+
expect(String(fields.removeExtra)).to.equal(undefined)
187+
}
188+
})
189+
})
190+
152191
it('should send minidump with updated extra parameters', function (done) {
153-
this.timeout(180000)
192+
this.timeout(specTimeout)
154193

155194
stopServer = startServer({
156195
callback (port) {
@@ -395,7 +434,7 @@ const waitForCrashReport = () => {
395434
})
396435
}
397436

398-
const startServer = ({ callback, processType, done }) => {
437+
const startServer = ({ callback, processType, done, preAssert, postAssert }) => {
399438
let called = false
400439
const server = http.createServer((req, res) => {
401440
const form = new multiparty.Form()
@@ -413,10 +452,12 @@ const startServer = ({ callback, processType, done }) => {
413452
expect(String(fields._productName)).to.equal('Zombies')
414453
expect(String(fields._companyName)).to.equal('Umbrella Corporation')
415454
expect(String(fields._version)).to.equal(app.getVersion())
455+
if (preAssert) preAssert(fields)
416456

417457
const reportId = 'abc-123-def-456-abc-789-abc-123-abcd'
418458
res.end(reportId, () => {
419459
waitForCrashReport().then(() => {
460+
if (postAssert) postAssert(reportId)
420461
expect(crashReporter.getLastCrashReport().id).to.equal(reportId)
421462
expect(crashReporter.getUploadedReports()).to.be.an('array').that.is.not.empty()
422463
expect(crashReporter.getUploadedReports()[0].id).to.equal(reportId)

spec/fixtures/module/crash.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@ process.crashReporter.start({
1010
}
1111
})
1212

13+
if (process.platform !== 'linux') {
14+
process.crashReporter.addExtraParameter('newExtra', 'newExtra')
15+
process.crashReporter.addExtraParameter('removeExtra', 'removeExtra')
16+
process.crashReporter.removeExtraParameter('removeExtra')
17+
}
18+
1319
process.nextTick(() => process.crash())

0 commit comments

Comments
 (0)
X Tutup