fix: persist session durably to survive reboot (#440)
Switch the session store SQLite connection from synchronous=NORMAL to synchronous=FULL. With WAL + NORMAL the last writes can sit unsynced in the WAL and be lost on a hard reboot / power loss, dropping the restored session. cc
This commit is contained in:
1 file changed
+9
-2
@@ -105,8 +105,15 @@ impl SessionStore {
|
|||||||
let conn = Connection::open(&db_path)
|
let conn = Connection::open(&db_path)
|
||||||
.map_err(|e| format!("Failed to open session database: {}", e))?;
|
.map_err(|e| format!("Failed to open session database: {}", e))?;
|
||||||
|
|
||||||
// Enable WAL mode for better concurrent access
|
// WAL mode for non-blocking reads/writes (ADR-002). synchronous=FULL,
|
||||||
conn.execute_batch("PRAGMA journal_mode=WAL; PRAGMA synchronous=NORMAL;")
|
// not NORMAL: in WAL mode NORMAL only fsyncs at a checkpoint, so a
|
||||||
|
// committed session survives an app restart (the WAL frames are still
|
||||||
|
// in the OS page cache) but is LOST on a hard reboot — the page cache
|
||||||
|
// is wiped and the frames were never fsync'd. FULL fsyncs every
|
||||||
|
// commit; the session DB is written infrequently so the cost is
|
||||||
|
// negligible. Without this, "restore session" silently breaks across
|
||||||
|
// reboots (issue #440).
|
||||||
|
conn.execute_batch("PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL;")
|
||||||
.map_err(|e| format!("Failed to set WAL mode: {}", e))?;
|
.map_err(|e| format!("Failed to set WAL mode: {}", e))?;
|
||||||
|
|
||||||
// Create tables
|
// Create tables
|
||||||
|
|||||||
Reference in new issue
Block a user