From ff9f679fcbc7a8ba5765a0a02e18dde1bef2b85e Mon Sep 17 00:00:00 2001 From: Simon Bernier St-Pierre Date: Fri, 7 Aug 2026 23:27:49 -0400 Subject: [PATCH] proper closing of sqlite connection --- src/main.rs | 4 ++++ src/sqlite.rs | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/main.rs b/src/main.rs index 53ba6d6..0ecaf9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -170,6 +170,10 @@ async fn main() -> Result<(), Box> { .with_graceful_shutdown(shutdown_signal()) .await?; info!("shutdown complete; closing database"); + // Explicitly close the pool so SQLite can checkpoint and remove the + // WAL/SHM sidecar files. Without this, the pool's background close task + // races with process exit and the sidecars can be left behind. + db.close().await; Ok(()) } diff --git a/src/sqlite.rs b/src/sqlite.rs index 867d641..d4b791f 100644 --- a/src/sqlite.rs +++ b/src/sqlite.rs @@ -74,6 +74,14 @@ impl SqliteDatabase { } impl SqliteDatabase { + /// Closes the connection pool, waiting for all connections to be released + /// and closed. This lets SQLite checkpoint and remove the WAL/SHM sidecar + /// files on a clean shutdown; without it, the pool's background close task + /// races with process exit and the sidecars may be left behind. + pub async fn close(&self) { + self.pool.close().await; + } + /// Runs `operation` inside a single transaction, committing on success and /// rolling back on error. Multiple repositories can participate in the same /// transaction so their writes commit together atomically.