Skip to content

fix(breadcrumbs): Unsubscribe system event breadcrumbs during background#7803

Open
denrase wants to merge 2 commits intomainfrom
fix/system-event-breadcrumbs-lifecycle
Open

fix(breadcrumbs): Unsubscribe system event breadcrumbs during background#7803
denrase wants to merge 2 commits intomainfrom
fix/system-event-breadcrumbs-lifecycle

Conversation

@denrase
Copy link
Copy Markdown
Collaborator

@denrase denrase commented Apr 14, 2026

📜 Description

Per Apple's docs (https://developer.apple.com/documentation/uikit/processing-queued-notifications?language=objc), iOS queues notifications while an app is suspended and delivers them on resume. The time we report them, might not align witht he time they were triggered, so they should not provide diagnostic value, so we might as well not use them. This also aligns us with Android behaviour, which implemented the equivalent issue in getsentry/sentry-java#4338.

This PR makes SentrySystemEventBreadcrumbs lifecycle-aware: unsubscribes from system event notifications on didEnterBackgroundNotification, re-subscribes on willEnterForegroundNotification. An isSubscribedToSystemEvents flag makes both operations idempotent.

Also fixes AND/OR matching bug in TestNSNotificationCenterWrapper.removeObserver(_:name:object:).

💡 Motivation and Context

This is being done with #4580 in mind. The reported SIGPIPE crashes show snprintf in the stack trace, but snprintf writes to a stack buffer and cannot generate SIGPIPE. Our hypothesis is that the signal originates elsewhere (e.g. stale network connections breaking after resume) and is delivered asynchronously to the main thread while it happens to be encoding a breadcrumb.

SentryCrash treats SIGPIPE as fatal, so the crash report captures whatever the thread was doing at signal delivery time. So while this will in all likleyhood not fix the underlying problem, it might reduce noise so we can find the root cause.

💚 How did you test it?

Unit tests.

📝 Checklist

You have to check all boxes before merging:

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

Per Apple's docs (https://developer.apple.com/documentation/uikit/processing-queued-notifications?language=objc), iOS queues notifications while an app is suspended and delivers them on resume. The time we report them, might not align witht he time they were triggered, so they should not provide diagnostic value, so we might as well not use them. This also aligns us with Android behaviour, which implemented the equivalent issue in getsentry/sentry-java#4338.

This PR makes SentrySystemEventBreadcrumbs lifecycle-aware: unsubscribes from system event notifications on didEnterBackgroundNotification, re-subscribes on willEnterForegroundNotification. An isSubscribedToSystemEvents flag makes both operations idempotent.

Also fixes AND/OR matching bug in TestNSNotificationCenterWrapper.removeObserver(_:name:object:).

This is being done with #4580 in mind. The reported SIGPIPE crashes show snprintf in the stack trace, but snprintf writes to a stack buffer and cannot generate SIGPIPE. Our hypothesis is that the signal originates elsewhere (e.g. stale network connections breaking after resume) and is delivered asynchronously to the main thread while it happens to be encoding a breadcrumb.

SentryCrash treats SIGPIPE as fatal, so the crash report captures whatever the thread was doing at signal delivery time. So while this will in all likleyhood not fix the underlying problem, it might reduce noise so we can find the root cause.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 14, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

  • (breadcrumbs) Unsubscribe system event breadcrumbs during background by denrase in #7803
  • Detect development builds via provisioning profile entitlement by denrase in #7702

Internal Changes 🔧

Deps

  • Bump actions/upload-pages-artifact from 4.0.0 to 5.0.0 by dependabot in #7789
  • Bump actions/github-script from 8.0.0 to 9.0.0 by dependabot in #7793

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 14, 2026

Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Fixes

- Unsubscribe system event breadcrumbs during background ([#7803](https://github.com/getsentry/sentry-cocoa/pull/7803))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against 0287ee3

@denrase denrase changed the title fix: Unsubscribe system event breadcrumbs during background fix(breadcrumbs): Unsubscribe system event breadcrumbs during background Apr 14, 2026
@denrase denrase marked this pull request as ready for review April 14, 2026 15:51
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.130%. Comparing base (6ea2191) to head (0287ee3).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #7803       +/-   ##
=============================================
- Coverage   85.416%   85.130%   -0.286%     
=============================================
  Files          487       487               
  Lines        29190     29221       +31     
  Branches     12625     12636       +11     
=============================================
- Hits         24933     24876       -57     
- Misses        4207      4293       +86     
- Partials        50        52        +2     
Files with missing lines Coverage Δ
...tils/Sources/TestNSNotificationCenterWrapper.swift 100.000% <100.000%> (ø)
...ons/Breadcrumbs/SentrySystemEventBreadcrumbs.swift 98.604% <100.000%> (+0.200%) ⬆️

... and 15 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ea2191...0287ee3. Read the comment docs.

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.

1 participant