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.