sentry-react-native: (ios only) codepush.restartApp triggers invalid OutOfMemory errors

Environment

How do you use Sentry? Sentry SaaS (sentry.io)

Which SDK and version? “@sentry/react-native”: “3.1.1”,

Steps to Reproduce

Our app is generating OutOfMemory The OS most likely terminated your app because it overused RAM. errors since upgrading to 3.1.1. We were previously on 2.4.2. The Podfile.lock shows that Sentry/Core (= 7.3.0) is installed. It previously showed: Sentry/Core (= 6.1.4).

The same logs show that there’s plenty of memory to go around, on some devices: Memory Size 5.6 GiB Usable Memory 3.9 GiB

Expected Result

These errors shouldn’t trigger.

I also posted about this here, but perhaps this issue should be reopened? https://github.com/getsentry/sentry-react-native/issues/1633 https://github.com/getsentry/sentry-cocoa/issues/1185

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 15
  • Comments: 76 (35 by maintainers)

Most upvoted comments

@sean-m-oleary, please upgrade to Sentry React Native v4, it should not break anything on your end.

We are using sentry-expo which is pinned to 3.1.1 so its not possible atm. We will wait for them to upgrade. In the meantime we can just set enableOutOfMemoryTracking to false right?

v3.2.1 is gonna be published in a bit and you can turn off the OutOfMemory detection by passing the enableOutOfMemoryTracking: false option, so we have a bit more time to investigate it, thanks.

Hi @philipphofmann , in the process of replying here (and adding comments & example values for environment, release, dist, etc), I realised that this issue stopped appearing with our latest release.

The only thing that changed between those two releases was react-native-reanimated@2.3.0-beta.2. We downgraded it to 2.2.3 because the beta version was causing other issues, and it seems that those versions don’t have the OOM error anymore. So that may be a good path to a minimal repro.

In the meantime, we could keep this open and I can report back whether this still happens in a week, after some further testing?

yep, https://github.com/getsentry/sentry-react-native/releases/tag/3.2.4 would one of you test it out using this latest version? thanks

@marandaneto seems like they just merged it 😄

I will test it again after https://github.com/getsentry/sentry-cocoa/pull/1487 gets merged and released.

Yes, exit(0) will generate an OOM. According to Apple, you shouldn’t do exit(0). Apple could reject your app because of that. @liamjones, which module does exit(0)? Is this common for React Native?

In the meantime, I will try to figure out if we can detect exit(0). This is related to https://github.com/getsentry/sentry-cocoa/issues/1252.

Thanks, PR is up https://github.com/getsentry/sentry-react-native/pull/2283 Releasing it within the next few minutes, please reopen it if you can still reproduce this issue.

The release is on its way https://github.com/getsentry/publish/issues/1135, but we have to wait for GH to fix an issue with the artifacts cache see https://www.githubstatus.com/.

I renamed the issue to concentrate it to what initially caused it and to concentrate it on an important use case that affects tons of users (everybody that uses react-native-codepush). Just to summarize the parts of this thread that seem useful to me:

  • calling codePush.restartApp(false); triggers this
  • codepush does not call exit() - see below for the stack of calls
  • this used to work in past releases of @sentry/react-native (e.g. 2.4.2)

I’m hoping that having a clean repro, and a previously working version should make it easy to debug this.

This is how restartApp works on iOS: This is the restartApp method which calls loadBundle which calls reload on the RN bridge

This report started showing over the last couple of days for us, a lot, but it matches the time we started testing our new Expo dev client builds coming from Expo Go.

It seems to be related to OTA updates, can’t really reproduce it reliably by swiping the app to force close it yet, and we also don’t* have reanimated in the project.

Let me know how we can help to debug this.

Edit: We have an offline fallback screen that has a reload action, we can reliably make this error happen by using the Reload App button that, that button calls Expo Updates reloadAsync method.

Relates to getsentry/sentry-cocoa#1618 @garethknowles by force-quitting do you mean directly in the IDE right?

By ‘force-quitting’ I mean by swiping up on the app switcher on the iPhone device: https://support.apple.com/en-gb/guide/iphone/iph83bfec492/ios

@philipphofmann let’s add both to the heuristics docs, the force quitting by the IDE and the exit(0), https://github.com/getsentry/sentry-docs/issues/4350 The OTA update, I will investigate again.

We’ve noticed the same issue when upgrading 3.2.3 to 3.4.0 - a massive increase of OutOfMemory errors on iOS.

We can reproduce the error ourselves by force-quitting the app, this is then being reported as OutOfMemory and sent to sentry on the next app start.

From 3.1.1 to 3.4.0 we did the following improvements for the Cocoa SDK on OOM:

Maybe OTA updates use exit(0) to force an app to restart. @aitorct, I don’t know how OTA looks from the user experience. Does RN reload the app when after OTA?

@BrodaNoel, do you use OTA as well?

The app can be manually reloaded after receiving an OTA update. I’ve been in touch with the Expo team and discussed a bit about this issue. I got told expo-updates does not use exit(0).

Here is how expo-updates reloads the app on iOS: https://github.com/expo/expo/blob/main/packages/expo-updates/ios/EXUpdates/EXUpdatesAppController.m#L198.

@adbl it seems to have fixed the OOMs when exit(0) is called for us.

@adbl I will update now as well and will let you know if out of memory still occurs.

I could not find any reference of the RN SDK or CodePush SDK doing it tho

When you say “doing it”, what does it refer to? Calling exit()? I don’t think that Codepush exits the app; it reloads the JS bundle: https://github.com/microsoft/react-native-code-push/blob/9947037a985a04927c64624318e4ce64d43d2049/ios/CodePush/CodePush.m#L543

For a minimal repro, you could start with Codepush’s demo app here https://github.com/microsoft/react-native-code-push/blob/9947037a985a04927c64624318e4ce64d43d2049/ios/CodePush/CodePush.m#L543

and add Sentry to it. You shouldn’t have to set up Codepush (get an account, etc), as calling restartApp(false) will suffice.

@liamjones unfortunately not, for now, disable it since we didn’t find the issue nor could reproduce it yet.

@philipphofmann do you know if the case of exit(0) is considered in our OOM detection?