Repository navigation
Description
Problem
pkgs/id/crates/id-cli/src/commands/serve.rs:209-217 reads and parses .iroh-serve.lock, checks whether that snapshot's process is alive, and then removes the shared path if the snapshot looks stale. The check and unlink are not tied to the same file contents or inode. Meanwhile, create_serve_lock() at serve.rs:245-261 writes a new lock to that path during server startup.
Interleaving: a discovery caller reads an old stale lock; a new serve instance writes its valid lock; the first caller finishes its stale check and remove_file(SERVE_LOCK) unlinks the new instance's lock. Later CLI commands then fail to discover/connect to the live server until it restarts. This is distinct from the fixed PID-incarnation, sentinel-PID, and EPERM cases (#3040, #2142, #2384): those validate liveness of the lock snapshot but do not prevent deleting a replacement written after the read.
Evidence
get_serve_info()reads at lines 209-211, checks the parsed PID/start time at 213-214, then unconditionally removes the shared path at 215-216.create_serve_lock()writes to the sameSERVE_LOCKpath at lines 245-261.- Fresh all-state title search for
serve-lockfound only id(serve): serve-lock staleness check tests pid existence, not serve identity — a reused pid wedges serve discovery on a dead endpoint #3040, id(serve): is_process_alive answers 'alive' for pid 0 and u32::MAX — a lock file with either pid is never stale and wedges serve discovery #2142, id(serve): is_process_alive treats EPERM as dead — a live foreign-owned serve's lock is deleted by get_serve_info #2384, and id(connectivity): await_home_relay and check_qad_order have no production caller — serve binds, writes its lock and prints ready with no home-relay wait, and the QAD relay-order refusal can never fire #3028; body search forget_serve_infofound the existing liveness issues, but no replacement/unlink race. Open PR title search found no race fix.
Acceptance criteria
- Stale cleanup can remove a lock only if the path still refers to the exact stale lock that was read (or use an equivalent atomic ownership/locking protocol); it must not unlink a replacement created by a concurrent serve startup.
- Add a deterministic regression test that pauses between stale-snapshot validation and cleanup, writes a fresh lock, resumes cleanup, and verifies the fresh lock remains discoverable.
- Preserve the current stale-lock cleanup behavior when the path still contains the stale snapshot.
Activity
developing-today commentedon Nov 20, 2026
CODE-4394