Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleCache never close databases even after a release #1890

Open
1 task
Tolriq opened this issue Nov 15, 2024 · 1 comment
Open
1 task

SimpleCache never close databases even after a release #1890

Tolriq opened this issue Nov 15, 2024 · 1 comment
Assignees

Comments

@Tolriq
Copy link
Contributor

Tolriq commented Nov 15, 2024

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 [email protected] after filing this issue.
@Tolriq
Copy link
Contributor Author

Tolriq commented Nov 15, 2024

As a side note there's another leak with cacheWriter #1755 (comment) but I do not really have a repro or reason for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants