cashapp / sqldelight

SQLDelight - Generates typesafe Kotlin APIs from SQL
https://cashapp.github.io/sqldelight/
Apache License 2.0
6.14k stars 515 forks source link

Connection does not close when using transaction #3687

Open kancko opened 1 year ago

kancko commented 1 year ago

SQLDelight Version

1.5.4

Application Operating System

Android

Describe the Bug

I noticed that the connection does not close when using transactions.

After a little research I found that the implementation of ConnectionManager in JdbcDriver is overridden by JdbcSqliteDriverConnectionManager

https://github.com/cashapp/sqldelight/blob/cb699fcc19632a70deeb2930470bcf09db625a42/drivers/sqlite-driver/src/main/kotlin/app/cash/sqldelight/driver/jdbc/sqlite/JdbcSqliteDriver.kt#L58-L70

Thus every time a new transaction is opened by JdbcSqliteDriver the connection remains open after its completion. So, in genereal the flow looks like this:

Does this mean that the user has to be responsible for closing the connection every time he uses a transaction? What is the point of overriding the functionality of JdbcDriver by JdbcSqliteDriverConnectionManager?

drakeet commented 1 month ago

This issue can still be reproduced in SQLDelight version 2.0.2.

This issue is more serious than expected. It causes db files to remain locked on Windows OS, preventing them from being renamed or deleted, which means we are unable to replace or reconnect a new database file. Could you please let us know if there are any plans to fix this issue? If needed, I can provide a small reproduction and debugging sample.

cc @JakeWharton

drakeet commented 1 month ago

Links: https://github.com/cashapp/sqldelight/issues/1832 https://github.com/cashapp/sqldelight/pull/2281 @AlecKazakova