Skip to content

fix(native): Skip scope flush during crash handling#1668

Merged
jpnurmi merged 2 commits intomasterfrom
jpnurmi/fix/native-flush
Apr 24, 2026
Merged

fix(native): Skip scope flush during crash handling#1668
jpnurmi merged 2 commits intomasterfrom
jpnurmi/fix/native-flush

Conversation

@jpnurmi
Copy link
Copy Markdown
Collaborator

@jpnurmi jpnurmi commented Apr 24, 2026

Came up in:

native_backend_flush_scope writes the current scope to state->event_path so the daemon has a fresh snapshot on crash. In the crash handler, however, any scope-mutating code path (e.g. sentry__scope_apply_to_event via SENTRY_WITH_SCOPE_MUT's flush-on-unlock) invokes flush_scope_func while native_backend_except is already writing the real crash event to the same file. The intermediate writes are wasted (the final write overwrites them) and add unnecessary file I/O in crash context.

Mirror the crashpad backend's existing guard: add a crashed atomic flag on the state, set it at the entry of except_func, and check it in flush_func so the flush becomes a no-op for the duration of crash handling:

//
if (!data->event_path || data->crashed.load(std::memory_order_relaxed)
|| !data->scope_flush.compare_exchange_strong(
expected, true, std::memory_order_acquire)) {
return;
}

jpnurmi and others added 2 commits April 24, 2026 09:19
`native_backend_flush_scope` writes the current scope to `state->event_path`
so the daemon has a fresh snapshot on crash. In the crash handler, however,
any scope-mutating code path (e.g. `sentry__scope_apply_to_event` via
`SENTRY_WITH_SCOPE_MUT`'s flush-on-unlock) invokes `flush_scope_func` while
`native_backend_except` is already writing the real crash event to the same
file. The intermediate writes are wasted (the final write overwrites them)
and add unnecessary file I/O in crash context.

Mirror the crashpad backend's existing guard: add a `crashed` atomic flag
on the state, set it at the entry of `native_backend_except`, and check
it in `native_backend_flush_scope` so the flush becomes a no-op for the
duration of crash handling.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jpnurmi jpnurmi requested a review from mujacica April 24, 2026 08:02
@jpnurmi jpnurmi merged commit 79911f8 into master Apr 24, 2026
61 of 63 checks passed
@jpnurmi jpnurmi deleted the jpnurmi/fix/native-flush branch April 24, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants