feat(nunciod): single-instance advisory lock on the DB path #346

Merged
KofTwentyTwo merged 1 commits from story/ws-c3-single-instance-lock into dev 2026-07-31 20:55:14 +00:00
1 Commits
Author SHA1 Message Date
James Maes 8b4e0384c2 feat(nunciod): single-instance advisory lock on the DB path
Acquire an exclusive OS advisory lock on a sidecar file beside the
database path (<db_path>.lock) before opening the store, so a second
nunciod pointed at the same database fails fast with an actionable
error instead of both instances writing to the same SQLite file.
Previously only an incidental gRPC port-bind collision offered any
protection against this.

Uses fs4 (flock on Unix, LockFileEx on Windows) since std has no
portable file-lock primitive. The guard is held for the process
lifetime and dropped at clean shutdown, releasing the lock; the OS
also releases it automatically if the process dies uncleanly, so
there is no PID-file staleness to reason about.

Refs #291
2026-07-31 15:52:22 -05:00