fix(native): Skip scope flush during crash handling#1668
Merged
Conversation
`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>
mujacica
approved these changes
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Came up in:
native_backend_flush_scopewrites the current scope tostate->event_pathso the daemon has a fresh snapshot on crash. In the crash handler, however, any scope-mutating code path (e.g.sentry__scope_apply_to_eventviaSENTRY_WITH_SCOPE_MUT's flush-on-unlock) invokesflush_scope_funcwhilenative_backend_exceptis 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
crashedatomic flag on the state, set it at the entry ofexcept_func, and check it inflush_funcso the flush becomes a no-op for the duration of crash handling:sentry-native/src/backends/sentry_backend_crashpad.cpp
Lines 265 to 270 in 82dbf13