pub struct SessionLock { /* private fields */ }Expand description
RAII guard preventing concurrent writes to the same JSONL session.
Owns the sentinel file <session_dir>/.lock for the lifetime of
the guard. On Drop, the sentinel is best-effort removed.
Stale-lock recovery: if the sentinel exists, its hostname matches
ours, and the recorded pid is not alive, acquire overwrites
it (logging a warning to stderr). If the hostname differs,
acquire refuses regardless of pid liveness — pid namespaces
across hosts aren’t comparable.
Why not flock(2): see g151 design — the sentinel approach
gives a better error message (“pid 12345 on host X is still
running”) and avoids NFS / iCloud / Dropbox flakiness.
Implementations§
Source§impl SessionLock
impl SessionLock
Sourcepub fn acquire(session_dir: &Path) -> Result<Self>
pub fn acquire(session_dir: &Path) -> Result<Self>
Acquire the lock for session_dir. Returns
std::io::Error wrapping a SessionLockBusy when
another live process holds it (or when an unrecoverable
cross-host lock is detected).