fix: send guid with linux crashes (#24881)
This commit is contained in:
parent
433956ce4f
commit
481b19bee6
4 changed files with 74 additions and 2 deletions
|
@ -40,7 +40,11 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(OS_LINUX)
|
#if defined(OS_LINUX)
|
||||||
|
#include "base/containers/span.h"
|
||||||
|
#include "base/files/file_util.h"
|
||||||
|
#include "base/guid.h"
|
||||||
#include "components/crash/core/app/breakpad_linux.h"
|
#include "components/crash/core/app/breakpad_linux.h"
|
||||||
|
#include "components/crash/core/common/crash_keys.h"
|
||||||
#include "v8/include/v8-wasm-trap-handler-posix.h"
|
#include "v8/include/v8-wasm-trap-handler-posix.h"
|
||||||
#include "v8/include/v8.h"
|
#include "v8/include/v8.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -81,6 +85,40 @@ bool IsCrashReporterEnabled() {
|
||||||
const std::map<std::string, std::string>& GetGlobalCrashKeys() {
|
const std::map<std::string, std::string>& GetGlobalCrashKeys() {
|
||||||
return GetGlobalCrashKeysMutable();
|
return GetGlobalCrashKeysMutable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base::FilePath GetClientIdPath() {
|
||||||
|
base::FilePath path;
|
||||||
|
base::PathService::Get(electron::DIR_CRASH_DUMPS, &path);
|
||||||
|
return path.Append("client_id");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ReadClientId() {
|
||||||
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||||
|
std::string client_id;
|
||||||
|
// "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".length == 36
|
||||||
|
if (!base::ReadFileToStringWithMaxSize(GetClientIdPath(), &client_id, 36) ||
|
||||||
|
client_id.size() != 36)
|
||||||
|
return std::string();
|
||||||
|
return client_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteClientId(const std::string& client_id) {
|
||||||
|
DCHECK_EQ(client_id.size(), 36u);
|
||||||
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||||
|
base::WriteFile(GetClientIdPath(), client_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetClientId() {
|
||||||
|
static base::NoDestructor<std::string> client_id;
|
||||||
|
if (!client_id->empty())
|
||||||
|
return *client_id;
|
||||||
|
*client_id = ReadClientId();
|
||||||
|
if (client_id->empty()) {
|
||||||
|
*client_id = base::GenerateGUID();
|
||||||
|
WriteClientId(*client_id);
|
||||||
|
}
|
||||||
|
return *client_id;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Start(const std::string& submit_url,
|
void Start(const std::string& submit_url,
|
||||||
|
@ -107,6 +145,7 @@ void Start(const std::string& submit_url,
|
||||||
? "node"
|
? "node"
|
||||||
: command_line->GetSwitchValueASCII(::switches::kProcessType);
|
: command_line->GetSwitchValueASCII(::switches::kProcessType);
|
||||||
#if defined(OS_LINUX)
|
#if defined(OS_LINUX)
|
||||||
|
::crash_keys::SetMetricsClientIdFromGUID(GetClientId());
|
||||||
auto& global_crash_keys = GetGlobalCrashKeysMutable();
|
auto& global_crash_keys = GetGlobalCrashKeysMutable();
|
||||||
for (const auto& pair : global_extra) {
|
for (const auto& pair : global_extra) {
|
||||||
global_crash_keys[pair.first] = pair.second;
|
global_crash_keys[pair.first] = pair.second;
|
||||||
|
|
|
@ -19,6 +19,7 @@ bool IsCrashReporterEnabled();
|
||||||
|
|
||||||
#if defined(OS_LINUX)
|
#if defined(OS_LINUX)
|
||||||
const std::map<std::string, std::string>& GetGlobalCrashKeys();
|
const std::map<std::string, std::string>& GetGlobalCrashKeys();
|
||||||
|
std::string GetClientId();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// JS bindings API; exposed publicly because it's also called from node_main.cc
|
// JS bindings API; exposed publicly because it's also called from node_main.cc
|
||||||
|
|
|
@ -722,8 +722,10 @@ void ElectronBrowserClient::AppendExtraCommandLineSwitches(
|
||||||
bool enable_crash_reporter = false;
|
bool enable_crash_reporter = false;
|
||||||
enable_crash_reporter = breakpad::IsCrashReporterEnabled();
|
enable_crash_reporter = breakpad::IsCrashReporterEnabled();
|
||||||
if (enable_crash_reporter) {
|
if (enable_crash_reporter) {
|
||||||
command_line->AppendSwitch(::switches::kEnableCrashReporter);
|
std::string switch_value =
|
||||||
std::string switch_value;
|
api::crash_reporter::GetClientId() + ",no_channel";
|
||||||
|
command_line->AppendSwitchASCII(::switches::kEnableCrashReporter,
|
||||||
|
switch_value);
|
||||||
for (const auto& pair : api::crash_reporter::GetGlobalCrashKeys()) {
|
for (const auto& pair : api::crash_reporter::GetGlobalCrashKeys()) {
|
||||||
if (!switch_value.empty())
|
if (!switch_value.empty())
|
||||||
switch_value += ",";
|
switch_value += ",";
|
||||||
|
|
|
@ -23,6 +23,7 @@ type CrashInfo = {
|
||||||
_productName: string
|
_productName: string
|
||||||
_version: string
|
_version: string
|
||||||
upload_file_minidump: Buffer // eslint-disable-line camelcase
|
upload_file_minidump: Buffer // eslint-disable-line camelcase
|
||||||
|
guid: string
|
||||||
mainProcessSpecific: 'mps' | undefined
|
mainProcessSpecific: 'mps' | undefined
|
||||||
rendererSpecific: 'rs' | undefined
|
rendererSpecific: 'rs' | undefined
|
||||||
globalParam: 'globalValue' | undefined
|
globalParam: 'globalValue' | undefined
|
||||||
|
@ -174,6 +175,35 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
|
||||||
expect(crash.rendererSpecific).to.be.undefined();
|
expect(crash.rendererSpecific).to.be.undefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('with guid', () => {
|
||||||
|
for (const processType of ['main', 'renderer', 'sandboxed-renderer']) {
|
||||||
|
it(`when ${processType} crashes`, async () => {
|
||||||
|
const { port, waitForCrash } = await startServer();
|
||||||
|
runCrashApp(processType, port);
|
||||||
|
const crash = await waitForCrash();
|
||||||
|
expect(crash.guid).to.be.a('string');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
it('is a consistent id', async () => {
|
||||||
|
let crash1Guid;
|
||||||
|
let crash2Guid;
|
||||||
|
{
|
||||||
|
const { port, waitForCrash } = await startServer();
|
||||||
|
runCrashApp('main', port);
|
||||||
|
const crash = await waitForCrash();
|
||||||
|
crash1Guid = crash.guid;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const { port, waitForCrash } = await startServer();
|
||||||
|
runCrashApp('main', port);
|
||||||
|
const crash = await waitForCrash();
|
||||||
|
crash2Guid = crash.guid;
|
||||||
|
}
|
||||||
|
expect(crash2Guid).to.equal(crash1Guid);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('with extra parameters', () => {
|
describe('with extra parameters', () => {
|
||||||
it('when renderer crashes', async () => {
|
it('when renderer crashes', async () => {
|
||||||
const { port, waitForCrash } = await startServer();
|
const { port, waitForCrash } = await startServer();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue