only close connection in case of reference count is 1

Due to how `execute` is implemented, it returns a `Connection` clone
which internally shares a turso_core::Connection with every other
Connection. Since `execute` returns `Connection` and immediatly it is
dropped, it will close connection, checkpoint and leave database in
weird state.
This commit is contained in:
Pere Diaz Bou
2025-07-08 15:17:15 +02:00
parent ee1ed1a6e6
commit 91107d364a

View File

@@ -296,9 +296,11 @@ impl Connection {
impl Drop for Connection {
fn drop(&mut self) {
self.conn
.close()
.expect("Failed to drop (close) connection");
if Arc::strong_count(&self.conn) == 1 {
self.conn
.close()
.expect("Failed to drop (close) connection");
}
}
}