Skip to content

lock: the absent-strike deadline rethrow does not mean "absent this whole time" #107

Closed

Description

@abogartz

Context

Found while re-reviewing #89 (2026-10-25). The deadline guard in src/lock.ts:

// Proceeding without the lock is the designed concession to
// contention — but never while the lock file has been absent this
// whole time
if (absentStrikes > 0) throw firstErr;

absentStrikes is reset to 0 by ANY probe that finds the lock file, so the condition as written means "the last probe proved absence", not "absent this whole time".

Consequences

  1. The ACL-denied directory the guard is named for is already covered ~130 ms earlier by the 8-strike throw; and where stat fails with a non-ENOENT label the counter never leaves 0 — that writer proceeds unguarded, which is exactly the case the comment promises to catch.
  2. In the healthy vanish-at-deadline race (create fails against a live holder, the holder unlinks before our probe, the budget expires in that same iteration) the writer now throws away an ordinary LOCK_WRITE that main would have kept. On Windows this shape is the common one, not the rare one.

Suggested fix

Track everSawHolder (set when a probe finds the lock) and gate the rethrow on !everSawHolder — that is what the comment describes.

Measurement so far

Healthy-filesystem stress (5 processes × 60 lock acquisitions, budgets 30 / 100 / 5000 ms, APFS): 0 writer errors — the false-positive tail was reasoned about, not reached on macOS.

Activity

  1. added
    bug
    on Oct 25, 2026
  2. WhollyMindless commented on Oct 25, 2026

    @WhollyMindless
    Contributor

    Taking this. The fix is your prescription, with one precision from the probe's own labels: everSawHolder gets set only by a stat that succeeds ("present"), not by the else branch as it's written today — that branch also swallows non-ENOENT stat failures, which is consequence 1's never-see-anything writer. So:

    • probe present -> everSawHolder = true, strikes reset (as today)
    • probe ENOENT -> strikes++ , 8-strike throw untouched (as today)
    • probe unknown -> strikes reset (as today), everSawHolder not set

    Deadline rethrow becomes !everSawHolder: consequence 2's healthy vanish-at-deadline race falls through to the designed proceed-unlocked concession, and consequence 1's EACCES-stat writer finally meets the comment's promise instead of the guard's absence.

    Red-first pins drive both races deterministically (scripted clock + scripted probe answers, no wall-clock races), Windows + Linux. PR shortly.

  3. added a commit that references this issue on Oct 26, 2026
  4. added a commit that references this issue on Oct 26, 2026
  5. abogartz-opencode-self-improvement commented on Oct 26, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.14.5 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

  6. added a commit that references this issue on Oct 26, 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

    bugreleased

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions