Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We're getting killed by the watch dog during background audio recording. Do we need to do anything special to avoid sentry running in the background? #4872

Open
bryan1anderson opened this issue Feb 19, 2025 · 4 comments

Comments

@bryan1anderson
Copy link

bryan1anderson commented Feb 19, 2025

Platform

iOS

Environment

Production

Installed

Swift Package Manager

Version

8.43.0

Xcode Version

16.2

Did it work on previous versions?

No response

Steps to Reproduce

Enable background audio recording
Background app

Expected Result

Sentry correctly limits its CPU usage to avoid anything that the watch dog would terminate. In our experience that essentially means 0% CPU usage, no UI updates, no networking.

Actual Result

We are getting unknown watch dog cleans ups.. and we're not sure if sentry is causing them.

Are you willing to submit a PR?

No response

@philipphofmann
Copy link
Member

Thanks for reporting this @bryan1anderson.

We are getting unknown watch dog cleans ups.. and we're not sure if sentry is causing them.

Please try not starting Sentry and double-check if you're still getting the watchdog cleanup. If yes, then our SDK isn't causing them. If no, please also share how you start the Sentry SDK to help us to investigate this. The easiest for us to investigate would be a small sample project to reproduce the problem if it isn't too much to ask.

And for clarification: What exactly do you mean by watch dog cleanup? Do you mean iOS terminating your app?

@bryan1anderson
Copy link
Author

bryan1anderson commented Feb 20, 2025

Sure thing! @philipphofmann
I'm referring to watchdog as iOS terminating our app for "reasons" https://developer.apple.com/documentation/xcode/addressing-watchdog-terminations

https://stackoverflow.com/questions/71656047/why-is-my-react-native-app-terminating-in-the-background-while-recording-ios-r
expo/expo#16807

We went on a less than fun journey to arrive at virtually 0% CPU usage before we started to reliably avoid background termination. This is not very well documented by Apple. But several developers solution was to destroy nearly everything when users transition to background recording.
Like remove all views, all publishers, kill timers, DispatchSource event handlers.. like EVERYTHING. The only thing alive is that AVAudioRecorder. This had a significant impact on the amount of reports of failed audio recordings, they went way down.

We added Sentry to understand just how significant that impact was.. and now we're not sure if we just have better observability or if observation itself is what is causing the influx of these newer reports.

I went on another sleuthing expedition to identify background CPU usage and found a few "heartbeat" tasks that were running and ended them.

The only part of the project I do NOT have visibility on for what happens in the background is Sentry.

These are hard to reproduce as iOS determines when this would be necessary by factors including age/condition of the battery.

Basically I'm looking to know:
If I log breadcrumbs to Sentry while the app is in the background, does Sentry have any provision to disable URL sessions/uploads until the app is resumed again? Is that default behavior?
How far do we need to go to arrive at virtual 0% cpu usage from Sentry in the background?
What is the easiest way to turn off Sentry when the app backgrounds?

Obviously I would prefer to keep it alive if I can essentially say: Sentry, you can only cache logs right now and you need to disable any repetitive "heartbeat" tasks and ONLY perform any work when I tell you to.

@philipphofmann
Copy link
Member

When your app moves to the background, the SentrySDK stops multiple services, such as tracking slow and frozen frames. I can't confirm that we are using 0% CPU when your app is in the background, but the overhead should be very low. It also depends on which features you enable in SentrySDK.start.

If I log breadcrumbs to Sentry while the app is in the background, does Sentry have any provision to disable URL sessions/uploads until the app is resumed again? Is that default behavior?

I'm sorry, I'm not sure what you mean by URL session/uploads.

How far do we need to go to arrive at virtual 0% cpu usage from Sentry in the background?

You can only achieve 0% usage if you close the SDK, by calling SentrySDK.close.

What is the easiest way to turn off Sentry when the app backgrounds?

Call SentrySDK.close.

@bryan1anderson
Copy link
Author

By uploads I meant whatever http requests you use to upload the logs. Okay SentrySDK.close sounds good.. I'll see what we can figure out. Thanks so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs Discussion
Development

No branches or pull requests

2 participants