sentry-react-native icon indicating copy to clipboard operation
sentry-react-native copied to clipboard

Sentry Watchdog causes a crashes writing to disk on the main thread

Open sena-mike opened this issue 1 year ago • 5 comments

OS:

  • [ ] Windows
  • [X] MacOS
  • [ ] Linux

Platform:

  • [X] iOS
  • [ ] Android

SDK:

  • [X ] react-native-sentry (<= 0.43.2)

SDK version: 5.6.0

react-native version: 0.71.8

Are you using Expo?

  • [X] Yes
  • [ ] No

Are you using sentry.io or on-premise?

  • [ ] sentry.io (SaaS)
  • [X] on-premise

If you are using sentry.io, please post a link to your issue so we can take a look:

[Link to issue]

Configuration:

(@sentry/react-native)

Sentry.init({
  dsn: 'https://[email protected]/...'
  // other options
});

or

(react-native-sentry)

Sentry.config(
  'https://[email protected]/...'
  // other options
 ).install();

I have the following issue:

[Description]

We get sentry crashes coming to the foreground due to the iOS watchdog. It seems the root cause of this is that Sentry writes to SentryWatchdogTerminationScopeObserver on the main queue:

Exception Type:  EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Termination Reason: FRONTBOARD 2343432205 
<RBSTerminateContext| domain:10 code:0x8BADF00D explanation:scene-update watchdog transgression: app<com.teslamotors.TeslaApp(D7971437-C6F2-4AD9-8635-802AF30D96D7)>:6951 exhausted real (wall clock) time allowance of 10.00 seconds
ProcessVisibility: Background
ProcessState: Running
WatchdogEvent: scene-update
WatchdogVisibility: Background
WatchdogCPUStatistics: (
"Elapsed total CPU time (seconds): 34.040 (user 19.730, system 14.310), 57% CPU",
"Elapsed application CPU time (seconds): 18.800, 31% CPU"
) reportType:CrashLog maxTerminationResistance:Interactive>
Screenshot 2024-04-19 at 5 07 43 PM

This is because the RNSentry native module uses the main queue and no dispatches to a background queue or background thread happens.

Writing to the main thread while transitioning to the background may cause crashes.

sena-mike avatar Apr 20 '24 00:04 sena-mike

Other times the crash is in removeFileAtPath: Screenshot 2024-04-19 at 5 12 26 PM

sena-mike avatar Apr 20 '24 00:04 sena-mike

Hey @sena-mike thanks for the report and the context, we'll investigate! Does this happen randomly or do you have a specific way to reproduce this?

kahest avatar Apr 23 '24 13:04 kahest

FYI, why the Cocoa SDK writes breadcrumbs to disk on the calling thread, which can be the main thread (SDK docs):

The SDK adds breadcrumbs to watchdog termination events by appending the breadcrumbs to an open file, which should have a marginal impact on your app's performance. Still, it skips adding some frequently changing context to avoid extra I/O, such as free memory, free storage, device orientation, charging status, battery level, etc.

philipphofmann avatar Apr 29 '24 10:04 philipphofmann

Hey @sena-mike thanks for the report and the context, we'll investigate! Does this happen randomly or do you have a specific way to reproduce this?

We see this crash happen mostly in TestFlight distribution, however it doesn't happen consistently for all users. Notably TestFlight will alert users that the crash occurred with a system notification even when the app is terminated by the CPU watch dog in the background.

If you'd like to opt out of this feature, you can do so using options: options.enableWatchdogTerminationTracking = false

Re the docs, it seems like opting out of watchdog termination tracking might prevent this from happening. Will investigate opting out on our end.

sena-mike avatar Apr 29 '24 16:04 sena-mike

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

getsantry[bot] avatar May 22 '24 07:05 getsantry[bot]