sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

OutOfMemory error logged when the app is manually killed after the SDK is closed.

Open mmerickel opened this issue 5 years ago • 21 comments

Environment

Which SDK and version? react-native-sentry 2.5.1 with sentry-cocoa 7.0.0 (but I checked and master probably has the same issue).

Steps to Reproduce

  1. [SentrySDK close] followed by exit(0);.
  2. App resumes, initializes the SentrySDK and logs OutOfMemory sentry event.

Expected Result

App should resume and not log an event because the SDK was closed during the crash. I can prevent this by disabling OOM tracking, but I would prefer to keep it on and have the SDK not record crashes that occurred after the SDK was closed. We re-initialize the SDK when the app launches again, and it compares to the state prior to the close, and determines it was a crash.

Actual Result

Sentry logged an OutOfMemory event.

The OS most likely terminated your app because it overused RAM.

Proposed Solution

The SentryAppState should be reset to willTerminate = YES when the SDK is closed.

mmerickel avatar Jun 18 '21 22:06 mmerickel

It looks like the problem is that currently the SentryOutOfMemoryTracker's stop method is invoked properly but it doesn't update the app state when stopping, and it should probably do it synchronously.

mmerickel avatar Jun 19 '21 00:06 mmerickel

For posterity my local fix for this is to invoke [self willTerminate] from [SentryOutOfMemoryTracker stop] and to modify the updateAppState method to be synchronous. It works but probably isn't fleshed out enough to be a PR.

mmerickel avatar Jun 21 '21 17:06 mmerickel

Thanks for reporting this, @mmerickel. This should be an easy fix in the SentryOutOfMemoryTracker. We just need to consider SentrySDK.close properly.

philippsuess avatar Jun 22 '21 10:06 philippsuess

we just upgraded from 6.x to 7 and are seeing this as well.

petergaultney avatar Jul 22 '21 13:07 petergaultney

PR #1272 should have addressed it. It was shipped on version 7.2.3

Please free free to reopen this if the issue persists

bruno-garcia avatar Sep 01 '21 14:09 bruno-garcia

I won't be able to confirm this soon but it looks like the fix that I was expecting and operating similarly to how we patched it internally - in a much hackier way. :-) Thank you all for working on this!

mmerickel avatar Sep 01 '21 14:09 mmerickel

Sadly, I'm still getting this error. We are using Sentry via its React Native integration, which is on 7.3.0. It does not seem to be a legitimate OOM, and we are only getting it in our staging version where we recently upgraded sentry to the latest version (2.4.2 => 3.1.1).

The Podfile.lock shows that Sentry/Core (= 7.3.0) is installed. It previously showed: Sentry/Core (= 6.1.4).

savv avatar Oct 12 '21 09:10 savv

@savv, have you managed to get around this issue?

I'm still seeing it on version "@sentry/react-native": "^3.1.1" with - Sentry (= 7.3.0)

mdiflorio avatar Oct 25 '21 04:10 mdiflorio

Yes, I am still seeing this issue

On Mon, 25 Oct 2021 at 07:41, Matt Di Florio @.***> wrote:

@savv https://github.com/savv, have you managed to get around this issue?

I'm still seeing it on version @.***/react-native": "^3.1.1" with `- Sentry (= 7.3.0)"

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/getsentry/sentry-cocoa/issues/1185#issuecomment-950522233, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFWP73FHJZ3NDSF7X3LK4LUITNXTANCNFSM466M3MUA .

savv avatar Oct 25 '21 05:10 savv

@mierz00 fyi - see here https://github.com/getsentry/sentry-react-native/issues/1830

savv avatar Oct 25 '21 13:10 savv

Still seeing this issue on the flutter sdk also.

derekpitts28 avatar Nov 02 '21 17:11 derekpitts28

Still seeing this issue on the flutter sdk also.

I am in the same situation.

mafreud avatar Nov 16 '21 06:11 mafreud

Thanks, for reporting this. I'm going to reopen this again. Most likely this is due to exit(0), which our current OOM logic can't detect reliably. We need to investigate how we can fix these false OOMs. Sorry about the inconvenience.

philippsuess avatar Nov 16 '21 13:11 philippsuess

@philipphofmann see https://github.com/getsentry/sentry-react-native/issues/1830#issuecomment-957871432 and https://github.com/getsentry/sentry-react-native/issues/1830#issuecomment-963348497

This does not exclusively happen with exit(0) (which is anyway not allowed on iOS).

savv avatar Nov 16 '21 13:11 savv

Thanks, @savv for pointing that out.

https://github.com/getsentry/sentry-react-native/issues/1830#issuecomment-957871432:

All Codepush users are seeing this issue whenever the app updates, even though the app is not terminated. So this is not just a prerelease/niche issue.

I found two potential problems. First, maybe we don't pass the release name properly down from hybrid SDKs to Cocoa https://github.com/getsentry/sentry-cocoa/blob/4499a316e36d7dfb355678e97303bacb32e8949f/Sources/Sentry/SentryOutOfMemoryLogic.m#L50-L53

Second, maybe we don't receive the willTerminateNotification properly from hybrid SDKs https://github.com/getsentry/sentry-cocoa/blob/4499a316e36d7dfb355678e97303bacb32e8949f/Sources/Sentry/SentryOutOfMemoryTracker.m#L70-L73

philippsuess avatar Nov 17 '21 13:11 philippsuess

Same problem here

rickafds avatar Nov 22 '21 14:11 rickafds

When closing the SDK we only remove the observers

https://github.com/getsentry/sentry-cocoa/blob/67eabc633b23d9a6727399910aea972deb1c02e3/Sources/Sentry/SentryOutOfMemoryTracker.m#L105-L110

but the SDK should properly set the app state so on the next start it doesn't generate an OOM.

philippsuess avatar Nov 24 '21 14:11 philippsuess

@philipphofmann I'm sorry if this is the wrong place to ask, but today I've received hundred of false OOM errors logged in Sentry. I haven't even executed the app that many times, so I'm thinking maybe they've been stemming from Xcode previews. I use native iOS with Sentry 7.11.0 with Xcode 13.3.

denizdogan avatar Mar 21 '22 18:03 denizdogan

Do you get these errors in debug or in release? @denizdogan

philippsuess avatar Mar 22 '22 15:03 philippsuess

@philipphofmann This is just during debugging/developing. It hasn't been released.

denizdogan avatar Mar 22 '22 15:03 denizdogan