rudderlabs / rudder-sdk-android

Android SDK for RudderStack - the Customer Data Platform for Developers.
https://www.rudderstack.com
Other
18 stars 29 forks source link

BUG : Strict mode error on the Initialization call #245

Closed bmoliveira closed 1 year ago

bmoliveira commented 1 year ago

Describe the bug

I started to get the warning that a resource was not being properly closed.

I noticed that a similar bug was reported in the past #55, but it appears that it has resurfaced?

Please provide the following information:

  1. A clear and concise description of what the bug is: A resource is not being closed.

  2. Share the event payload: At initialization time and/or during some random events.

  3. Offer a minimal viable example to reproduce the issue: Check initialization code.

  4. Indicate if the SDK is being initialized or events are being created on a separate thread or coroutine apart from the main thread Initialization on the main thread during onCreate()

  5. Specify if the issue is specific to a particular device model or OS version: Happening on multiple devices, but I'm doing debug on Pixel 6a with the Android 14 (build UPB4.230623.005)

  6. Include the error's stack trace Check stack trace section

  7. Mention the date when the issue began I'm not certain exactly, but started to debug it today (25/07/2023).

To Reproduce

  1. Setup strict policy, otherwise only a small log is shown:
            StrictMode.setVmPolicy(
                VmPolicy.Builder()
                    .detectLeakedClosableObjects()
                    .penaltyLog()
                    .build(),
            )
  2. Initialize Android SDK.
  3. See the error.

Stack trace

11:41:48.347  D  StrictMode policy violation: android.os.strictmode.LeakedClosableViolation: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
                    at android.os.StrictMode$AndroidCloseGuardReporter.report(StrictMode.java:1994)
                    at dalvik.system.CloseGuard.warnIfOpen(CloseGuard.java:336)
                    at java.util.zip.Inflater.finalize(Inflater.java:407)
                    at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:339)
                    at java.lang.Daemons$FinalizerDaemon.processReference(Daemons.java:324)
                    at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:300)
                    at java.lang.Daemons$Daemon.run(Daemons.java:145)
                    at java.lang.Thread.run(Thread.java:1012)
                 Caused by: java.lang.Throwable: Explicit termination method 'end' not called
                    at dalvik.system.CloseGuard.openWithCallSite(CloseGuard.java:288)
                    at dalvik.system.CloseGuard.open(CloseGuard.java:257)
                    at java.util.zip.Inflater.<init>(Inflater.java:122)
                    at com.android.okhttp.okio.GzipSource.<init>(GzipSource.java:64)
                    at com.android.okhttp.internal.http.HttpEngine.unzip(HttpEngine.java:484)
                    at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:661)
                    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:475)
                    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
                    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542)
                    at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:106)
                    at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:30)
                    at com.rudderstack.android.sdk.core.RudderNetworkManager.getResult(RudderNetworkManager.java:128)
                    at com.rudderstack.android.sdk.core.RudderNetworkManager.sendNetworkRequest(RudderNetworkManager.java:116)
                    at com.rudderstack.android.sdk.core.RudderNetworkManager.sendNetworkRequest(RudderNetworkManager.java:90)
                    at com.rudderstack.android.sdk.core.RudderServerConfigManager.downloadConfig(RudderServerConfigManager.java:67)
                    at com.rudderstack.android.sdk.core.RudderServerConfigManager.lambda$fetchConfig$0$com-rudderstack-android-sdk-core-RudderServerConfigManager(RudderServerConfigManager.java:48)
                    at com.rudderstack.android.sdk.core.RudderServerConfigManager$$ExternalSyntheticLambda0.run(Unknown Source:2)
                    at java.lang.Thread.run(Thread.java:1012) 
11:41:48.383  D  StrictMode policy violation: android.os.strictmode.LeakedClosableViolation: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
                    at android.os.StrictMode$AndroidCloseGuardReporter.report(StrictMode.java:1994)
                    at dalvik.system.CloseGuard.warnIfOpen(CloseGuard.java:336)
                    at android.database.CursorWindow.finalize(CursorWindow.java:185)
                    at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:339)
                    at java.lang.Daemons$FinalizerDaemon.processReference(Daemons.java:324)
                    at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:300)
                    at java.lang.Daemons$Daemon.run(Daemons.java:145)
                    at java.lang.Thread.run(Thread.java:1012)
                 Caused by: java.lang.Throwable: Explicit termination method 'CursorWindow.close' not called
                    at dalvik.system.CloseGuard.openWithCallSite(CloseGuard.java:288)
                    at dalvik.system.CloseGuard.open(CloseGuard.java:257)
                    at android.database.CursorWindow.<init>(CursorWindow.java:150)
                    at android.database.CursorWindow.<init>(CursorWindow.java:122)
                    at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:203)
                    at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:139)
                    at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:132)
                    at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:238)
                    at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:277)
                    at com.rudderstack.android.sdk.core.DBPersistentManager.checkIfStatusColumnExists(DBPersistentManager.java:473)
                    at com.rudderstack.android.sdk.core.DBPersistentManager.checkForMigrations(DBPersistentManager.java:495)
                    at com.rudderstack.android.sdk.core.EventRepository.initializeDbManager(EventRepository.java:174)
                    at com.rudderstack.android.sdk.core.EventRepository.<init>(EventRepository.java:103)
                    at com.rudderstack.android.sdk.core.RudderClient.getInstance(RudderClient.java:140)
                    at <redacted>.RudderstackHandler$rudderClient$2.invoke(RudderstackHandler.kt:17)
                    at <redacted>.RudderstackHandler$rudderClient$2.invoke(RudderstackHandler.kt:16)
                    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
                    at <redacted>.RudderstackHandler.getRudderClient(RudderstackHandler.kt:16)
                    at <redacted>RudderstackHandler.postEvent(RudderstackHandler.kt:29)
                    at <redacted>.AnalyticsManagerImpl.postEvent(AnalyticsManagerImpl.kt:13)
                    at <redacted>.AnalyticsManager$DefaultImpls.postEvent(AnalyticsManager.kt:20)
                    at <redacted>.AnalyticsManagerImpl.postEvent(AnalyticsManagerImpl.kt:8)
                    at <redacted>Application$onCreate$4.onResume(Application.kt:99)
                    at androidx.lifecycle.DefaultLifecycleObserverAdapter.onStateChanged(DefaultLifecycleObserverAdapter.kt:26)
                    at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.kt:314)
                    at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.kt:251)
                    at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.kt:287)
                    at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.kt:136)
                    at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.kt:119)
                    at androidx.lifecycle.ProcessLifecycleOwner.activityResumed$lifecycle_process_release(ProcessLifecycleOwner.kt:106)
                    at androidx.lifecycle.ProcessLifecycleOwner$attach$1$onActivityPreCreated$1.onActivityPostResumed(ProcessLifecycleOwner.kt:164)
                    at android.app.Activity.dispatchActivityPostResumed(Activity.java:1496)
                    at android.app.Activity.performResume(Activity.java:8776)
                    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4951)
                    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4994)
                    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:57)
                    at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
11:41:48.406  D  StrictMode policy violation: android.os.strictmode.LeakedClosableViolation: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
                    at android.os.StrictMode$AndroidCloseGuardReporter.report(StrictMode.java:1994)
                    at dalvik.system.CloseGuard.warnIfOpen(CloseGuard.java:336)
                    at android.database.AbstractCursor.finalize(AbstractCursor.java:531)
                    at android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:291)
                    at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:339)
                    at java.lang.Daemons$FinalizerDaemon.processReference(Daemons.java:324)
                    at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:300)
                    at java.lang.Daemons$Daemon.run(Daemons.java:145)
                    at java.lang.Thread.run(Thread.java:1012)
                 Caused by: java.lang.Throwable: Explicit termination method 'AbstractCursor.close' not called
                    at dalvik.system.CloseGuard.openWithCallSite(CloseGuard.java:288)
                    at dalvik.system.CloseGuard.open(CloseGuard.java:257)
                    at android.database.AbstractCursor.<init>(AbstractCursor.java:227)
                    at android.database.AbstractWindowedCursor.<init>(AbstractWindowedCursor.java:39)
                    at android.database.sqlite.SQLiteCursor.<init>(SQLiteCursor.java:98)
                    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:52)
                    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1714)
                    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1653)
                    at com.rudderstack.android.sdk.core.DBPersistentManager.checkIfStatusColumnExists(DBPersistentManager.java:472)
                    at com.rudderstack.android.sdk.core.DBPersistentManager.checkForMigrations(DBPersistentManager.java:495)
                    at com.rudderstack.android.sdk.core.EventRepository.initializeDbManager(EventRepository.java:174)
                    at com.rudderstack.android.sdk.core.EventRepository.<init>(EventRepository.java:103)
                    at com.rudderstack.android.sdk.core.RudderClient.getInstance(RudderClient.java:140)
                    at <redacted>.RudderstackHandler$rudderClient$2.invoke(RudderstackHandler.kt:17)
                    at <redacted>.RudderstackHandler$rudderClient$2.invoke(RudderstackHandler.kt:16)
                    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
                    at <redacted>.RudderstackHandler.getRudderClient(RudderstackHandler.kt:16)
                    at <redacted>.RudderstackHandler.postEvent(RudderstackHandler.kt:29)
                    at <redacted>.AnalyticsManagerImpl.postEvent(AnalyticsManagerImpl.kt:13)
                    at <redacted>.AnalyticsManager$DefaultImpls.postEvent(AnalyticsManager.kt:20)
                    at <redacted>.AnalyticsManagerImpl.postEvent(AnalyticsManagerImpl.kt:8)
                    at <redacted>Application$onCreate$4.onResume(Application.kt:99)
                    at androidx.lifecycle.DefaultLifecycleObserverAdapter.onStateChanged(DefaultLifecycleObserverAdapter.kt:26)
                    at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.kt:314)
                    at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.kt:251)
                    at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.kt:287)
                    at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.kt:136)
                    at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.kt:119)
                    at androidx.lifecycle.ProcessLifecycleOwner.activityResumed$lifecycle_process_release(ProcessLifecycleOwner.kt:106)
                    at androidx.lifecycle.ProcessLifecycleOwner$attach$1$onActivityPreCreated$1.onActivityPostResumed(ProcessLifecycleOwner.kt:164)
                    at android.app.Activity.dispatchActivityPostResumed(Activity.java:1496)
                    at android.app.Activity.performResume(Activity.java:8776)
                    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4951)
                    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4994)
                    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:57)

Expected behavior

Not having resource not closed exceptions.

Screenshots

N/A

Version of the Android SDK

com.rudderstack.android.sdk:core version 1.14.0

Mobile device mode integration

  1. Warning found on many by I'm debugging it locally on a Pixel 6a with the Android 14 (build UPB4.230623.005)
  2. SDK directly.

SDK initialisation snippet


  private val rudderClient = RudderClient.getInstance(
        context,
        writeKey,
        RudderConfig.Builder()
            .withDataPlaneUrl(dataPlane)
            .withTrackLifecycleEvents(false)
            .withRecordScreenViews(false)
            .build(),
    )
itsdebs commented 1 year ago

@bmoliveira can you try with the latest version 1.17.0? We have already fixed this

MoumitaM commented 1 year ago

@bmoliveira Have you tried the latest version? let us know

bmoliveira commented 1 year ago

Sorry for the delay responding, I was on PTO until yesterday, I was finally able to test the update and is working without the warnings.

Thank you for the fix and the responses 🚀