Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: db connection starvation via tokio::spawn and ImmediateTx::drop (#3007)

Louis Beaumontcf32f77125bf
diff --git a/crates/screenpipe-db/src/db.rs b/crates/screenpipe-db/src/db.rs
index 692515b5f..9003b5fa2 100644
--- a/crates/screenpipe-db/src/db.rs
+++ b/crates/screenpipe-db/src/db.rs
@@ -118,6 +118,7 @@ impl Drop for ImmediateTx {
// If ROLLBACK fails, we detach as a last resort (better to leak one
// slot than poison the pool with a stuck transaction).
warn!("ImmediateTx dropped without commit — rolling back");
+ let permit = self._write_permit.take(); // Hold permit until rollback completes
tokio::spawn(async move {
match sqlx::query("ROLLBACK").execute(&mut *conn).await {
Ok(_) => {
@@ -132,8 +133,8 @@ impl Drop for ImmediateTx {
let _raw = conn.detach();
}
}
+ drop(permit); // Release the write permit so other writers can proceed
});
- // Release the write permit so other writers can proceed
}
}
}