fix(breadcrumbs): Unregister SystemEventsBroadcastReceiver when entering background#4338
Merged
fix(breadcrumbs): Unregister SystemEventsBroadcastReceiver when entering background#4338
Conversation
romtsn
commented
Apr 15, 2025
| SentryLevel.INFO, | ||
| "androidx.lifecycle is not available, AppLifecycleIntegration won't be installed", | ||
| e); | ||
| SentryLevel.WARNING, |
Member
Author
There was a problem hiding this comment.
Unrelated to this PR, but I just noticed while testing no androidx.lifecycle case that it's noisy and decided to change that
Contributor
Performance metrics 🚀
|
markushi
approved these changes
Apr 16, 2025
Member
markushi
left a comment
There was a problem hiding this comment.
Awesome, I left two small comments!
romtsn
added a commit
that referenced
this pull request
Jul 8, 2025
denrase
added a commit
to getsentry/sentry-cocoa
that referenced
this pull request
Apr 14, 2026
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.
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.
📜 Description
Some background
Android 14 introduced new behavior for broadcast receivers, and our SystemEvents receiver (used to add breadcrumbs like screen on/off, airplane mode change, etc.) is falling under this. What's happening is the process gets cached for some period of time (can be hours or days) and after getting uncached it receives all those pending broadcasts in a quick succession which most likely causes ANRs. This also correlates with the numbers we see in SDKCD where the biggest number of ANRs is coming from Android 14+.
I did some tests locally and it is indeed happening as described on the screenshot.
SystemEventsBreadcrumbsIntegrationis now lifecycle-aware:💡 Motivation and Context
Closes #4294
Internal customer case
💚 How did you test it?
Manually + automated
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps