From 45f52a82bf6600f9935d798ca9a942879461b707 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sun, 5 Jul 2026 17:25:00 +0200 Subject: [PATCH 1/7] feat: Send crashpad event updates over IPC Send serialized crash event and external crash report data to the Crashpad handler for file writes. Keep the existing file-write fallback for payloads that cannot be sent through the handler IPC. Co-Authored-By: OpenAI Codex --- external/crashpad | 2 +- src/backends/sentry_backend_crashpad.cpp | 60 +++++++++++++++++++----- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/external/crashpad b/external/crashpad index a40e3bdc1..fde1cf56b 160000 --- a/external/crashpad +++ b/external/crashpad @@ -1 +1 @@ -Subproject commit a40e3bdc151f8dcd0bec6d3fb07901d3fa728e49 +Subproject commit fde1cf56b8f44ff81494e975c61ddfb090eba03c diff --git a/src/backends/sentry_backend_crashpad.cpp b/src/backends/sentry_backend_crashpad.cpp index 61a44a170..37171855a 100644 --- a/src/backends/sentry_backend_crashpad.cpp +++ b/src/backends/sentry_backend_crashpad.cpp @@ -214,8 +214,36 @@ crashpad_register_wer_module( } #endif +static int +write_attachment(crashpad_state_t *state, const sentry_path_t *path, + const char *data, size_t size) +{ + if (!path || !state || !state->client) { + return 1; + } + return state->client->WriteAttachment( + base::FilePath(SENTRY_PATH_PLATFORM_STR(path)), + std::string(data, size)) + ? 0 + : 1; +} + +static int +append_attachment(crashpad_state_t *state, const sentry_path_t *path, + const char *data, size_t size) +{ + if (!path || !state || !state->client) { + return 1; + } + return state->client->AppendAttachment( + base::FilePath(SENTRY_PATH_PLATFORM_STR(path)), + std::string(data, size)) + ? 0 + : 1; +} + static void -flush_scope_to_event(const sentry_path_t *event_path, +flush_scope_to_event(crashpad_state_t *state, const sentry_path_t *event_path, const sentry_options_t *options, sentry_value_t crash_event) { SENTRY_WITH_SCOPE (scope) { @@ -231,7 +259,7 @@ flush_scope_to_event(const sentry_path_t *event_path, return; } - int rv = sentry__path_write_buffer(event_path, mpack, mpack_size); + int rv = write_attachment(state, event_path, mpack, mpack_size); sentry_free(mpack); if (rv != 0) { @@ -242,8 +270,9 @@ flush_scope_to_event(const sentry_path_t *event_path, // Prepares an envelope with DSN, event ID, and session if available, for an // external crash reporter. static void -flush_external_crash_report( - const sentry_options_t *options, const sentry_uuid_t *crash_event_id) +flush_external_crash_report(crashpad_state_t *state, + const sentry_path_t *external_report_path, const sentry_options_t *options, + const sentry_uuid_t *crash_event_id) { sentry_envelope_t *envelope = sentry__envelope_new(); if (!envelope) { @@ -258,7 +287,13 @@ flush_external_crash_report( sentry__envelope_set_header(envelope, "cache_dir", sentry_value_new_string(options->run->cache_path->path)); } - sentry__run_write_external(options->run, envelope); + + size_t size = 0; + char *serialized = sentry_envelope_serialize(envelope, &size); + if (serialized) { + write_attachment(state, external_report_path, serialized, size); + sentry_free(serialized); + } sentry_envelope_free(envelope); } @@ -334,9 +369,10 @@ crashpad_backend_flush_scope( sentry_value_set_by_key( event, "level", sentry__value_new_level(SENTRY_LEVEL_FATAL)); - flush_scope_to_event(data->event_path, options, event); + flush_scope_to_event(data, data->event_path, options, event); if (data->external_report_path) { - flush_external_crash_report(options, &data->crash_event_id); + flush_external_crash_report( + data, data->external_report_path, options, &data->crash_event_id); } data->scope_flush.store(false, std::memory_order_release); #endif @@ -386,9 +422,10 @@ flush_scope_from_handler( } // now we are the sole flusher and can flush into the crash event - flush_scope_to_event(state->event_path, options, crash_event); + flush_scope_to_event(state, state->event_path, options, crash_event); if (state->external_report_path) { - flush_external_crash_report(options, &state->crash_event_id); + flush_external_crash_report(state, state->external_report_path, options, + &state->crash_event_id); } } @@ -796,6 +833,7 @@ crashpad_backend_startup( sentry_free(filename); if (data->external_report_path) { + sentry__path_create_dir_all(options->run->external_path); crash_reporter = base::FilePath( SENTRY_PATH_PLATFORM_STR(options->external_crash_reporter)); crash_envelope = base::FilePath( @@ -968,8 +1006,8 @@ crashpad_backend_add_breadcrumb(sentry_backend_t *backend, } int rv = first_breadcrumb - ? sentry__path_write_buffer(breadcrumb_file, mpack, mpack_size) - : sentry__path_append_buffer(breadcrumb_file, mpack, mpack_size); + ? write_attachment(data, breadcrumb_file, mpack, mpack_size) + : append_attachment(data, breadcrumb_file, mpack, mpack_size); sentry_free(mpack); if (rv != 0) { From ea01e1840833201cf5aae81f7c7b507ec738b63b Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 21 Jul 2026 18:20:44 +0200 Subject: [PATCH 2/7] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 865e4cedd..c9ed84759 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Windows: add WER integration for syncing tags and attachments to WER. ([#1837](https://github.com/getsentry/sentry-native/pull/1837)) - Report `cache_overflow` discards due to `cache_max_items` or `cache_max_size`. ([#1884](https://github.com/getsentry/sentry-native/pull/1884)) +- Crashpad/Windows: optimize scope flushes for crash events and external crash reports. ([#1841](https://github.com/getsentry/sentry-native/pull/1841)) **Fixes**: From df6fcc12363a5493920440f361a877743cd3050b Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 24 Jul 2026 13:45:11 +0200 Subject: [PATCH 3/7] use base::span to prevent copies --- external/crashpad | 2 +- src/backends/sentry_backend_crashpad.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/external/crashpad b/external/crashpad index fde1cf56b..bbd95ecd7 160000 --- a/external/crashpad +++ b/external/crashpad @@ -1 +1 @@ -Subproject commit fde1cf56b8f44ff81494e975c61ddfb090eba03c +Subproject commit bbd95ecd7720f2995e8c12ff4bc925792fe8b862 diff --git a/src/backends/sentry_backend_crashpad.cpp b/src/backends/sentry_backend_crashpad.cpp index 37171855a..7667f3e30 100644 --- a/src/backends/sentry_backend_crashpad.cpp +++ b/src/backends/sentry_backend_crashpad.cpp @@ -223,7 +223,7 @@ write_attachment(crashpad_state_t *state, const sentry_path_t *path, } return state->client->WriteAttachment( base::FilePath(SENTRY_PATH_PLATFORM_STR(path)), - std::string(data, size)) + base::as_bytes(base::make_span(data, size))) ? 0 : 1; } @@ -237,7 +237,7 @@ append_attachment(crashpad_state_t *state, const sentry_path_t *path, } return state->client->AppendAttachment( base::FilePath(SENTRY_PATH_PLATFORM_STR(path)), - std::string(data, size)) + base::as_bytes(base::make_span(data, size))) ? 0 : 1; } From 4f74a1684f4cf823d16d3df64dcab5f570b18a5b Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 24 Jul 2026 15:29:29 +0200 Subject: [PATCH 4/7] dump crashpad --- external/crashpad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/crashpad b/external/crashpad index bbd95ecd7..e5917a1ab 160000 --- a/external/crashpad +++ b/external/crashpad @@ -1 +1 @@ -Subproject commit bbd95ecd7720f2995e8c12ff4bc925792fe8b862 +Subproject commit e5917a1ab2f563cb411d24e305a6da5cfdb58589 From 73d458b83231fa61636e3c229c1308c675e279d1 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 24 Jul 2026 16:19:48 +0200 Subject: [PATCH 5/7] bump crashpad --- external/crashpad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/crashpad b/external/crashpad index e5917a1ab..28495ae2b 160000 --- a/external/crashpad +++ b/external/crashpad @@ -1 +1 @@ -Subproject commit e5917a1ab2f563cb411d24e305a6da5cfdb58589 +Subproject commit 28495ae2bdb10c18338928fb5db4cc223e015e31 From 9048c4299f1c82611d52295c01798e73dc93e546 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 24 Jul 2026 19:04:45 +0200 Subject: [PATCH 6/7] bump crashpad --- external/crashpad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/crashpad b/external/crashpad index 28495ae2b..7ac234db3 160000 --- a/external/crashpad +++ b/external/crashpad @@ -1 +1 @@ -Subproject commit 28495ae2bdb10c18338928fb5db4cc223e015e31 +Subproject commit 7ac234db350fcea825fd7e4ae680e4ad86191781 From b02b89a1d67efdf1aa7aec86859d910e71799ac7 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 24 Jul 2026 19:31:09 +0200 Subject: [PATCH 7/7] check mkdir result --- src/backends/sentry_backend_crashpad.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/backends/sentry_backend_crashpad.cpp b/src/backends/sentry_backend_crashpad.cpp index 7667f3e30..71fabc3d7 100644 --- a/src/backends/sentry_backend_crashpad.cpp +++ b/src/backends/sentry_backend_crashpad.cpp @@ -833,11 +833,17 @@ crashpad_backend_startup( sentry_free(filename); if (data->external_report_path) { - sentry__path_create_dir_all(options->run->external_path); - crash_reporter = base::FilePath( - SENTRY_PATH_PLATFORM_STR(options->external_crash_reporter)); - crash_envelope = base::FilePath( - SENTRY_PATH_PLATFORM_STR(data->external_report_path)); + if (sentry__path_create_dir_all(options->run->external_path) == 0) { + crash_reporter = base::FilePath( + SENTRY_PATH_PLATFORM_STR(options->external_crash_reporter)); + crash_envelope = base::FilePath( + SENTRY_PATH_PLATFORM_STR(data->external_report_path)); + } else { + SENTRY_ERRORF( + "mkdir failed: \"%s\"", options->run->external_path->path); + sentry__path_free(data->external_report_path); + data->external_report_path = nullptr; + } } }