proper closing of sqlite connection
This commit is contained in:
@@ -170,6 +170,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.with_graceful_shutdown(shutdown_signal())
|
.with_graceful_shutdown(shutdown_signal())
|
||||||
.await?;
|
.await?;
|
||||||
info!("shutdown complete; closing database");
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,14 @@ impl SqliteDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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
|
/// Runs `operation` inside a single transaction, committing on success and
|
||||||
/// rolling back on error. Multiple repositories can participate in the same
|
/// rolling back on error. Multiple repositories can participate in the same
|
||||||
/// transaction so their writes commit together atomically.
|
/// transaction so their writes commit together atomically.
|
||||||
|
|||||||
Reference in New Issue
Block a user