androidx / androidx/media

SimpleCache never close databases even after a release

Open
#1,890 1 comment 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Nov 21, 2024.

bug needs triage
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

Version

Media3 main branch

More version details

No response

Devices that reproduce the issue

All

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

Create a SimpleCache instance:

SimpleCache(
                            File(context.externalCacheDir ?: context.cacheDir, "exoplayer"),
                            LeastRecentlyUsedCacheEvictor(cacheSize),
                            StandaloneDatabaseProvider(context),
                        )

use it.

call .release() on it.

The database is not closed and if you use StrictMode on Android it crashes with:

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. (Ask Gemini)
                                                                                                    	at android.os.StrictMode$AndroidCloseGuardReporter.report(StrictMode.java:2009)
                                                                                                    	at dalvik.system.CloseGuard.warnIfOpen(CloseGuard.java:336)
                                                                                                    	at android.database.sqlite.SQLiteDatabase.dispose(SQLiteDatabase.java:544)
                                                                                                    	at android.database.sqlite.SQLiteDatabase.finalize(SQLiteDatabase.java:528)
                                                                                                    	at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:370)
                                                                                                    	at java.lang.Daemons$FinalizerDaemon.processReference(Daemons.java:350)
                                                                                                    	at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:322)
                                                                                                    	at java.lang.Daemons$Daemon.run(Daemons.java:131)
                                                                                                    	at java.lang.Thread.run(Thread.java:1012)
                                                                                                    Caused by: java.lang.Throwable: Explicit termination method 'close' not called
                                                                                                    	at dalvik.system.CloseGuard.openWithCallSite(CloseGuard.java:288)
                                                                                                    	at dalvik.system.CloseGuard.open(CloseGuard.java:257)
                                                                                                    	at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:1192)
                                                                                                    	at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:1171)
                                                                                                    	at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1035)
                                                                                                    	at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1024)
                                                                                                    	at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:373)
                                                                                                    	at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:340)
                                                                                                    	at androidx.media3.datasource.cache.CachedContentIndex$DatabaseStorage.exists(CachedContentIndex.java:788)
                                                                                                    	at androidx.media3.datasource.cache.CachedContentIndex.initialize(CachedContentIndex.java:203)
                                                                                                    	at androidx.media3.datasource.cache.SimpleCache.initialize(SimpleCache.java:549)
                                                                                                    	at androidx.media3.datasource.cache.SimpleCache.access$000(SimpleCache.java:51)
                                                                                                    	at androidx.media3.datasource.cache.SimpleCache$1.run(SimpleCache.java:235)

From a quick check of the code, this is actually true, plenty of call to get database, but no close anywhere.

Expected result

Databases are closed and resources freed.

Actual result

They are not

Media

N/A

Bug Report
  • You will email the zip file produced by adb bugreport to android-media-github@google.com after filing this issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.