Skip to content

JdbcSqliteDriver transactions leave JDBC connection open #4078

@alenz316

Description

@alenz316

SQLDelight Version

1.5.5

Application Operating System

JVM

Describe the Bug

Using the file-based JdbcSqliteDriver, which uses ThreadedConnectionManager internally, has inconsistent connection handling for queries in and outside of transactions. Outside of a transaction, queries always close the connection. However, queries in a transaction will leave the connection open post-transaction. Additionally, these open connections are not closed when the db is close()'d either; which is a problem on Windows because no file level operations can occur if the file is "open".

Code example:

val file = File(realPath)
val database = SQLDelightDatabase(driver = JdbcSqliteDriver("jdbc:sqlite:$realPath"), ...)
database.transaction { } // Leaves a connection open
database.close() // Does nothing, the connection is still open
file.delete() // This will fail to delete the file on Windows because of the open connection
database.queries.getData().executeAsOneOrNull() // Closes the connection
file.delete() // Will now succeed 

Stacktrace

No stacktrace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions