Skip to content

[WIP] fix!: apply scope before on_crash callback - #2119

Open
jpnurmi wants to merge 13 commits into
masterfrom
jpnurmi/ref/crash-apply
Open

jpnurmi wants to merge 13 commits into
masterfrom
jpnurmi/ref/crash-apply

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Fixes: #2102

Use a shared MessagePack stream for attachment manifests. The native
backend uses the manifest for attachments generally, while both
out-of-process crash handlers can also use it for crash-time hint
attachments that cannot cross backend IPC. This lets Crashpad consume
those attachments without adding JSON support.

Stream attachment objects directly to avoid format-specific conversion
and buffer the complete manifest for a single file write. Median release
benchmarks measured write/read improvements over legacy JSON of 17%/6%
for one attachment, 74%/17% for 10, and 86%/24% for 100:

                    1 attachment   10 attachments   100 attachments
  MessagePack write       2.3 us           2.4 us            11.8 us
  JSON write              2.7 us           8.9 us            82.6 us
  MessagePack read        1.3 us           5.6 us            54.1 us
  JSON read               1.4 us           6.8 us            71.1 us

Keep legacy JSON compatibility private to the native daemon so it can
still consume manifests written by older SDK versions.
Accept hints in `sentry_scope_capture_event` and pass them to
`before_send`. Keep `sentry_capture_event` unchanged.

Merge hint and scope attachments before `before_send` and
`before_send_feedback`, then use the resulting hint attachments in the
envelope. Add `sentry_hint_remove_attachment` and
`sentry_hint_clear_attachments` to filter attachments without modifying
scopes.

BREAKING CHANGE: `before_send` callbacks now take `sentry_hint_t *`
instead of `void *` for the hint parameter. `sentry_scope_capture_event`
now requires a hint argument; pass `NULL` when no hint is needed.
Scope attachment changes inside either callback no longer affect the
current event; modify the hint instead.

Close: #2098
@jpnurmi
jpnurmi added this pull request to stack #2113 September 21, 2026 16:17
Comment thread src/sentry_core.c
@codecov

codecov Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.87097% with 102 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.16%. Comparing base (6f6faf1) to head (f9cc9af).

Additional details and impacted files
@@                     Coverage Diff                      @@
##           jpnurmi/feat/crash-hints    #2119      +/-   ##
============================================================
- Coverage                     75.32%   75.16%   -0.17%     
============================================================
  Files                           104      104              
  Lines                         28069    28294     +225     
  Branches                       5126     5152      +26     
============================================================
+ Hits                          21143    21267     +124     
- Misses                         5593     5692      +99     
- Partials                       1333     1335       +2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jpnurmi
jpnurmi force-pushed the jpnurmi/ref/crash-apply branch from 6418ff1 to 72281f2 Compare September 21, 2026 19:30
@jpnurmi jpnurmi changed the title feat!: apply scope before on_crash callback fix!: apply scope before on_crash callback Sep 21, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread CHANGELOG.md Outdated
@jpnurmi
jpnurmi force-pushed the jpnurmi/ref/crash-apply branch from 72281f2 to f9cc9af Compare September 21, 2026 19:43

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f9cc9af. Configure here.

crash_event = options->on_crash_func(
&uctx, crash_event, &hint, options->on_crash_data);
crash_event = sentry__invoke_on_crash(
options, &uctx, crash_event, &hint, false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crashpad lock held during on_crash

Medium Severity

lock_scope_from_handler now runs before on_crash and never releases scope_flush. A fault inside the callback re-enters the handler while that lock is still held, so Windows spins forever on scope_flush and Linux hits _exit before the scoped event is written.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f9cc9af. Configure here.

Base automatically changed from jpnurmi/feat/crash-hints to master September 22, 2026 12:55
@jpnurmi jpnurmi changed the title fix!: apply scope before on_crash callback [WIP] fix!: apply scope before on_crash callback Sep 22, 2026
@linear-code

linear-code Bot commented Sep 23, 2026

Copy link
Copy Markdown

NATIVE-230

This branch has not been deployed

No deployments
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.

on_crash receives an event without scope data

2 participants