getsentry / sentry-java

A Sentry SDK for Java, Android and other JVM languages.
https://docs.sentry.io/
MIT License
1.16k stars 435 forks source link

OutOfMemoryError causes crash when tracing instrumentation enabled for InstrumentationFeature.DATABASE #2853

Closed ZeeshanShabbir closed 1 year ago

ZeeshanShabbir commented 1 year ago

Integration

sentry-android

Build System

Gradle

AGP Version

7.4.2

Proguard

Enabled

Version

6.25.0

Steps to Reproduce

Hi, we are getting reports that the app crashes because of sentry integration with DB.

1- Enable tracing Instrumentation and add InstrumentationFeature.DATABASE

Expected Result

The app shouldn't crash while performing CRUD operations

Actual Result

App crashes while performing CRUD operations.

Fatal Exception: java.lang.OutOfMemoryError:
at java.lang.Object.internalClone(Object.java)
       at java.lang.Object.clone(Object.java:259)
       at java.util.concurrent.CopyOnWriteArrayList.toArray(CopyOnWriteArrayList.java:330)
       at java.util.ArrayList.<init>(ArrayList.java:191)
       at io.sentry.SentryTracer.hasAllChildrenFinished(SentryTracer.java:529)
       at io.sentry.SentryTracer.lambda$createChild$2(SentryTracer.java:386)
       at io.sentry.Span.finish(Span.java:228)
       at io.sentry.Span.finish(Span.java:175)

Another stacktrace


Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 112696 byte allocation with 9 free bytes and 9B until OOM, target footprint 268435456, growth limit 268435456
       at java.lang.Object.internalClone(Object.java)
       at java.lang.Object.clone(Object.java:259)
       at java.util.concurrent.CopyOnWriteArrayList.toArray(CopyOnWriteArrayList.java:330)
       at java.util.ArrayList.<init>(ArrayList.java:191)
       at io.sentry.SentryTracer.getLatestActiveSpan(SentryTracer.java:707)
       at io.sentry.Scope.getSpan(Scope.java:201)
       at io.sentry.Hub.getSpan(Hub.java:769)
       at io.sentry.HubAdapter.getSpan(HubAdapter.java:220)
       at io.sentry.android.sqlite.SQLiteSpanManager.performSql(SQLiteSpanManager.kt:30)
       at io.sentry.android.sqlite.SentrySupportSQLiteDatabase.query(SentrySupportSQLiteDatabase.kt:60)
       at androidx.room.RoomDatabase.query(RoomDatabase.kt:490)
       at androidx.room.util.DBUtil.query(DBUtil.kt:75)
romtsn commented 1 year ago

@ZeeshanShabbir thanks for the report, are you actually able to reproduce this yourself, or this is coming from the play console rather?

ZeeshanShabbir commented 1 year ago

@ZeeshanShabbir thanks for the report, are you actually able to reproduce this yourself, or this is coming from the play console rather?

It is coming from a few reports from Crashlytics for a few users. I am unable to reproduce this myself but from the stack trace you can see OOM is when doing CRUD.

romtsn commented 1 year ago

@ZeeshanShabbir indeed, but this doesn't mean that our instrumentation is the one consuming all the memory, it just happened to be the last one that is allocating memory before the OOM. Anyway, there's definitely something wrong from our side, we're gonna fix it, but this is likely a duplicate of https://github.com/getsentry/sentry-java/issues/2815, so I'm gonna close this one. Please track the progress there. Thank you 🙏