sqldelight / sqldelight

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

Connection does not close when using transaction #3687

Open kancko opened 2 years ago

kancko commented 2 years 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 3 months 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.

drakeet commented 3 months ago

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

drakeet commented 1 month ago

It seems to have been fixed here: https://github.com/sqldelight/sqldelight/pull/5205

RaVbaker commented 2 days ago

@hfhbd @AlecKazakova any idea when next version will get released with this fix?