sentry-android-gradle-plugin icon indicating copy to clipboard operation
sentry-android-gradle-plugin copied to clipboard

Tracing Instrumentation Crash

Open MarioNoll opened this issue 2 years ago • 5 comments

Gradle Version

7.4.2

AGP Version

7.1.2

Code Minifier/Optimizer

R8

Version

3.0.1

Sentry SDK Version

5.7.2

Steps to Reproduce

Apply the sentry gradle plugin.

Expected Result

The app does not crash with tracing instrumentation enabled.

Actual Result

With tracing instrumentation enabled we can see that users are facing crashes in our Android app, we can't reproduce them though.

Looking at the crash distribution it only seems to affect older Android versions (7.0 is our minimum), also the devices seem to be Huawei exclusively.

84% - Android 8.0.0 13% - Android 8.1.0 1% - Android 7.0

android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=52 (# cursors opened by this proc=52)
    at android.database.CursorWindow.<init>(CursorWindow.java:110)
    at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
    at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:138)
    at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:132)
    at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:219)
    at android.database.AbstractCursor.moveToNext(AbstractCursor.java:268)
    at com.squareup.sqldelight.android.AndroidCursor.next(SourceFile:273)
    at com.squareup.sqldelight.Query.executeAsOneOrNull(SourceFile:160)
    at com.yazio.shared.repo.GenericDao$flow$4$1.invokeSuspend(SourceFile:77)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(SourceFile:33)
    at kotlinx.coroutines.DispatchedTask.run(SourceFile:106)
    at kotlinx.coroutines.internal.LimitedDispatcher.run(SourceFile:39)
    at kotlinx.coroutines.scheduling.TaskImpl.run(SourceFile:95)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(SourceFile:571)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(SourceFile:750)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(SourceFile:678)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(SourceFile:665)

MarioNoll avatar May 20 '22 10:05 MarioNoll

@looploooop thanks for reporting. There are no Sentry stack traces related to it, how do you know it's the Sentry instrumentation crashing your App? thanks

marandaneto avatar May 20 '22 12:05 marandaneto

We had instrumentation disabled before due to https://github.com/getsentry/sentry-android-gradle-plugin/issues/299 As this ticket has been resolved we removed the code that disabled instrumentation, which is when these crashes appeared. Disabling the instrumentation again fixed it for us in a new release.

MarioNoll avatar May 20 '22 12:05 MarioNoll

Thanks for the feedback, we'll take a look into it.

marandaneto avatar May 21 '22 09:05 marandaneto

@looploooop thanks for the report, we'll try to investigate the issue. Out of curiosity, are you actually using performance instrumentation with Sentry or just happened to have this flag enabled by default?

romtsn avatar May 23 '22 07:05 romtsn

@romtsn We're not using performance instrumentation as of now, but just kept the flag in it's default setting.

MarioNoll avatar May 23 '22 08:05 MarioNoll

@lbloder do you have an update on this topic?

markushi avatar Nov 30 '22 14:11 markushi

@MarioNoll I had a look into our instrumentation code and we only instrument the FrameworkSQLiteDatabase and FrameworkSQLiteStatement classes and both seem to be correct after Instrumentation.

Because we aren't changing how cursors are opened or closed, I don't think this is something caused by our DB instrumentation.

There's an issue from 2020 on the SQLDelight Repo regarding a similar problem. They figured it has to do with the oem implementation of sqlite (https://github.com/cashapp/sqldelight/issues/1603), which would make sense, as the issue seems to happen on Huawei devices only.

You could try to run you app in Strict mode with detectLeakedSqlLiteObjects() enabled to check if there are any cursors that are not closed.

lbloder avatar Dec 01 '22 15:12 lbloder

I'm gonna close this, @MarioNoll feel free to reopen if you still find out its our fault here. thanks

romtsn avatar Dec 02 '22 08:12 romtsn