Skip to main content

save_last_session_snapshot

Function save_last_session_snapshot 

Source
pub(crate) fn save_last_session_snapshot(store: &Store, snapshot: Value) -> bool
Expand description

Persist a snapshot as the durable “last session” record, overwriting whatever was there before. Best-effort: a write failure is logged, never propagated — this must never block the close it rides alongside.

Reads-then-writes the singleton Client row inside a single with_tx (reagentx P1 on PR #2560): the two used to be separate store.get_all/store.update calls, unlike persist_subscriber’s window handlers which already wrap this exact shape in a transaction. A concurrent write to Client between the read and the write here (e.g. another in-flight CloseWindow pruning windowids, or a second concurrent snapshot save/clear) would silently lose whichever change didn’t win the race — a classic lost-update. with_tx holds the store’s connection lock for the whole read+write, so no other caller can observe or write an intermediate state. Returns whether the write actually landed. Callers on the clean-close path (window_close.rs) intentionally discard this — that path is documented best-effort, and must never let a snapshot failure block the close it is riding along with. The OS-shutdown path (handle_save_session_snapshot below) is different: it has nothing else to do after this call, so it uses the result to report whether the flush actually succeeded rather than reporting success unconditionally.