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

cache db was leaked #66

Open
Tracked by #2331
laomo opened this issue Aug 3, 2020 · 4 comments
Open
Tracked by #2331

cache db was leaked #66

laomo opened this issue Aug 3, 2020 · 4 comments
Assignees

Comments

@laomo
Copy link

laomo commented Aug 3, 2020

Summary
cache db was leaked.

Version
v2.2.2

Description
SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.my.package/databases/cache.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.

@martinbonnin
Copy link
Contributor

Hi! Sorry for ultra late response. Can you share more details about how to reproduce this issue?

@lwasyl
Copy link

lwasyl commented Dec 10, 2020

Hey @martinbonnin not OP but we also see these logs in UI tests. We do call

apolloClient.clearHttpCache()
apolloClient.clearNormalizedCache()

after each test to clear the state, we also interrupt all currently running flows (btw is there a better way to basically stop everything Apollo is doing?). However after this, it seems that database is still open, so it leaks between the tests. I poked around but couldn't find an API to close the database properly after using

@nhickf
Copy link

nhickf commented Nov 11, 2024

Hello @martinbonnin I encountered the same issue, is there any fix on this issue?

@BoD
Copy link
Collaborator

BoD commented Nov 12, 2024

It appears this can happen when an SQLiteConnection is garbage collected, without its close() method having been called first - which Apollo Kotlin never calls.

In practice, these connections are held by the SQLDelight driver, which is held by the SqlNormalizedCacheFactory, which is held by the ApolloClient. I managed to reproduce by removing references to a client and calling System.gc().

We should propagate ApolloClient.close() to the SQLDelight driver.

I don't believe this error should actually be too worrisome, but in the meantime, it's a bit hacky, but there's a way to close your connections thanks to the configure callback:

// Keep a reference to your db
var sqliteDatabase: SupportSQLiteDatabase? = null

val apolloClient = ApolloClient.Builder()
    .normalizedCache(
        SqlNormalizedCacheFactory(
            this,
            configure = {
                sqliteDatabase = it
            }
        )
    )

and then when you've finished using your client:

apolloClient.close()
sqliteDatabase?.close()

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

No branches or pull requests

5 participants