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

chore: add V8 crash information to crashReporter #24866

Merged
merged 2 commits into from Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions shell/common/api/electron_api_v8_util.cc
Expand Up @@ -133,6 +133,16 @@ std::vector<v8::Local<v8::Value>> GetWeaklyTrackedValues(v8::Isolate* isolate) {
}
return locals;
}

// This causes a fatal error by creating a circular extension dependency.
void TriggerFatalErrorForTesting(v8::Isolate* isolate) {
static const char* aDeps[] = {"B"};
v8::RegisterExtension(std::make_unique<v8::Extension>("A", "", 1, aDeps));
static const char* bDeps[] = {"A"};
v8::RegisterExtension(std::make_unique<v8::Extension>("B", "", 1, bDeps));
v8::ExtensionConfiguration config(1, bDeps);
v8::Context::New(isolate, &config);
}
#endif

void Initialize(v8::Local<v8::Object> exports,
Expand Down Expand Up @@ -160,6 +170,7 @@ void Initialize(v8::Local<v8::Object> exports,
&RequestGarbageCollectionForTesting);
dict.SetMethod("isSameOrigin", &IsSameOrigin);
#ifdef DCHECK_IS_ON
dict.SetMethod("triggerFatalErrorForTesting", &TriggerFatalErrorForTesting);
dict.SetMethod("getWeaklyTrackedValues", &GetWeaklyTrackedValues);
dict.SetMethod("clearWeaklyTrackedValues", &ClearWeaklyTrackedValues);
dict.SetMethod("weaklyTrackValue", &WeaklyTrackValue);
Expand Down
17 changes: 14 additions & 3 deletions shell/common/api/electron_bindings.cc
Expand Up @@ -31,15 +31,26 @@
#include "shell/common/node_includes.h"
#include "third_party/blink/renderer/platform/heap/process_heap.h" // nogncheck

#if !defined(MAS_BUILD)
#include "shell/common/crash_keys.h"
#endif

namespace electron {

namespace {

// Called when there is a fatal error in V8, we just crash the process here so
// we can get the stack trace.
void FatalErrorCallback(const char* location, const char* message) {
void V8FatalErrorCallback(const char* location, const char* message) {
LOG(ERROR) << "Fatal error in V8: " << location << " " << message;
ElectronBindings::Crash();

#if !defined(MAS_BUILD)
crash_keys::SetCrashKey("electron.v8-fatal.message", message);
crash_keys::SetCrashKey("electron.v8-fatal.location", location);
#endif

volatile int* zero = nullptr;
*zero = 0;
}

} // namespace
Expand Down Expand Up @@ -86,7 +97,7 @@ void ElectronBindings::BindProcess(v8::Isolate* isolate,

void ElectronBindings::BindTo(v8::Isolate* isolate,
v8::Local<v8::Object> process) {
isolate->SetFatalErrorHandler(FatalErrorCallback);
isolate->SetFatalErrorHandler(V8FatalErrorCallback);

gin_helper::Dictionary dict(isolate, process);
BindProcess(isolate, &dict, metrics_.get());
Expand Down
34 changes: 31 additions & 3 deletions spec-main/api-crash-reporter-spec.ts
Expand Up @@ -38,6 +38,8 @@ type CrashInfo = {
globalParam: 'globalValue' | undefined
addedThenRemoved: 'to-be-removed' | undefined
longParam: string | undefined
'electron.v8-fatal.location': string | undefined
'electron.v8-fatal.message': string | undefined
}

function checkCrash (expectedProcessType: string, fields: CrashInfo) {
Expand Down Expand Up @@ -247,6 +249,32 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
expect(crash.rendererSpecific).to.equal('rs');
expect(crash.addedThenRemoved).to.be.undefined();
});

it('contains v8 crash keys when a v8 crash occurs', async () => {
const { remotely } = await startRemoteControlApp();
const { port, waitForCrash } = await startServer();

await remotely((port: number) => {
require('electron').crashReporter.start({
submitURL: `http://127.0.0.1:${port}`,
ignoreSystemCrashHandler: true
});
}, [port]);

remotely(() => {
const { BrowserWindow } = require('electron');
const bw = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
bw.loadURL('about:blank');
bw.webContents.executeJavaScript('process._linkedBinding(\'electron_common_v8_util\').triggerFatalErrorForTesting()');
});

const crash = await waitForCrash();
expect(crash.prod).to.equal('Electron');
expect(crash._productName).to.equal('remote-control');
expect(crash.process_type).to.equal('renderer');
expect(crash['electron.v8-fatal.location']).to.equal('v8::Context::New()');
expect(crash['electron.v8-fatal.message']).to.equal('Circular extension dependency');
});
});
});

Expand Down Expand Up @@ -447,7 +475,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
await remotely(() => {
require('electron').crashReporter.start({
submitURL: 'http://127.0.0.1',
extra: { 'extra1': 'hi' }
extra: { extra1: 'hi' }
Copy link
Member Author

Choose a reason for hiding this comment

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

auto-changed by lint-staged

});
});
const parameters = await remotely(() => require('electron').crashReporter.getParameters());
Expand Down Expand Up @@ -480,8 +508,8 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
crashReporter.start({ submitURL: 'http://' });
const bw = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
bw.loadURL('about:blank');
await bw.webContents.executeJavaScript(`require('electron').crashReporter.addExtraParameter('hello', 'world')`);
return bw.webContents.executeJavaScript(`require('electron').crashReporter.getParameters()`);
await bw.webContents.executeJavaScript('require(\'electron\').crashReporter.addExtraParameter(\'hello\', \'world\')');
return bw.webContents.executeJavaScript('require(\'electron\').crashReporter.getParameters()');
Copy link
Member Author

Choose a reason for hiding this comment

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

auto-changed by lint-staged

});
if (process.platform === 'linux') {
// On Linux, 'getParameters' will also include the global parameters,
Expand Down
1 change: 1 addition & 0 deletions typings/internal-ambient.d.ts
Expand Up @@ -43,6 +43,7 @@ declare namespace NodeJS {
weaklyTrackValue(value: any): void;
clearWeaklyTrackedValues(): void;
getWeaklyTrackedValues(): any[];
triggerFatalErrorForTesting(): void;
}

type DataPipe = {
Expand Down