Skip to content

fix(id/serve): stale-lock cleanup can unlink a replacement serve lock #12094

Closed

Description

@dezren39

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

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

  1. added
    kind/bug
    task/triage
    source/creator
    priority/normal
    on Nov 20, 2026
  2. developing-today commented on Nov 20, 2026

    @developing-today
    Contributor
  3. added
    app/id
    effort/xs
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/ideffort/xskind/bugpriority/normalsource/creatorstatus:donetask/triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions