From f582ccfc95f621112a1de3d3680acd64b647e66a Mon Sep 17 00:00:00 2001 From: cobalt-github-releaser-bot <95661244+cobalt-github-releaser-bot@users.noreply.github.com> Date: Tue, 19 Mar 2024 13:25:21 -0700 Subject: [PATCH] Cherry pick PR #2598: Make loader app withstand failed Crashpad db init (#2626) Refer to the original PR: https://github.com/youtube/cobalt/pull/2598 Because of a missed nullptr check, the loader app currently crashes if initialization of the Crashpad database fails during installation of the Crashpad handler. There will be further investigation and improvements here but for now, the loader app will continue to load Cobalt - just without crash reporting for the current session. We shoud add unit tests for this module soon. It would probably be best to stub out the Starboard calls, which will require a little refactoring. b/329458881 b/326436503 Change-Id: Ibb9e9abe5e0295ddbc6d139f11d4ab6b3a1fbb4c Co-authored-by: Holden Warriner --- third_party/crashpad/wrapper/wrapper.cc | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/third_party/crashpad/wrapper/wrapper.cc b/third_party/crashpad/wrapper/wrapper.cc index 4d16aef5e0a2..93eb5ae42d6a 100644 --- a/third_party/crashpad/wrapper/wrapper.cc +++ b/third_party/crashpad/wrapper/wrapper.cc @@ -94,11 +94,16 @@ base::FilePath GetDatabasePath() { return base::FilePath(crashpad_directory_path.c_str()); } -void InitializeCrashpadDatabase(const base::FilePath database_directory_path) { +bool InitializeCrashpadDatabase(const base::FilePath database_directory_path) { std::unique_ptr<::crashpad::CrashReportDatabase> database = ::crashpad::CrashReportDatabase::Initialize(database_directory_path); + if (!database) { + return false; + } + ::crashpad::Settings* settings = database->GetSettings(); settings->SetUploadsEnabled(true); + return true; } std::string GetProductName() { @@ -190,8 +195,8 @@ void InstallCrashpadHandler(bool start_at_crash, const base::FilePath handler_path = GetPathToCrashpadHandlerBinary(); if (!SbFileExists(handler_path.value().c_str())) { - LOG(WARNING) << "crashpad_handler not at expected location of " - << handler_path.value(); + LOG(ERROR) << "crashpad_handler not at expected location of " + << handler_path.value(); return; } @@ -207,7 +212,17 @@ void InstallCrashpadHandler(bool start_at_crash, const std::map platform_info = GetPlatformInfo(); default_annotations.insert(platform_info.begin(), platform_info.end()); - InitializeCrashpadDatabase(database_directory_path); + if (!InitializeCrashpadDatabase(database_directory_path)) { + LOG(ERROR) << "Failed to initialize Crashpad database"; + + // As we investigate b/329458881 we may find that it's safe to continue with + // installation of the Crashpad handler here with the hope that the handler, + // when it runs, doesn't experience the same failure when initializing the + // Crashpad database. For now it seems safer to just give up on crash + // reporting for this particular Cobalt session. + return; + } + client->SetUnhandledSignals({}); if (start_at_crash)