From 91107d364a012d3f2b630e490e03ae5ca169f185 Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Tue, 8 Jul 2025 15:17:15 +0200 Subject: [PATCH] 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. --- bindings/python/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index 6606c8dd0..eb56d429d 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -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"); + } } }