Skip to content

Fall back to a portable lock when flock is unavailable#931

Open
alistair3149 wants to merge 1 commit into
masterfrom
fix/portable-port-lock
Open

Fall back to a portable lock when flock is unavailable#931
alistair3149 wants to merge 1 commit into
masterfrom
fix/portable-port-lock

Conversation

@alistair3149

Copy link
Copy Markdown
Member

Driven by @alistair3149: flagged macOS as a supported platform, chose flock-with-fallback over a pure rewrite or requiring flock as a prerequisite, and directed the code review.
Context: the NeoWiki dev-env Makefile and Docker/scripts port-allocation tooling, plus a code review of the change.
Written by Claude Code, Opus 4.8

set-port.sh serialized concurrent port allocation with flock(1) (util-linux), which stock macOS does not ship, so make dev aborted on first run with flock: command not found on a supported platform.

Keep flock where present — its kernel-managed lock auto-releases on process death, even on SIGKILL — and fall back to an atomic, per-user directory mutex where it is absent (e.g. macOS). The fallback recovers a lock orphaned by a crashed run via the holder PID's liveness, stealing through an atomic rename so a concurrent run cannot delete a freshly taken lock.

test-set-port.sh exercises both paths: the existing cases run under real flock, while two new cases force the fallback (allocation works without flock; a stale lock from a dead holder is recovered).

set-port.sh serialized concurrent port allocation with flock(1) (util-linux),
which stock macOS does not ship, so `make dev` aborted on first run with
`flock: command not found` on a supported platform.

Keep flock where present -- its kernel-managed lock auto-releases on process
death -- and fall back to an atomic, per-user directory mutex where it is absent
(e.g. macOS). The fallback recovers a lock orphaned by a crashed run via the
holder PID's liveness, stealing through an atomic rename so a concurrent run
cannot delete a freshly taken lock.

test-set-port.sh exercises both paths: existing cases run under real flock, while
two new cases force the fallback (allocation works without flock; a stale lock
from a dead holder is recovered).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@alistair3149 alistair3149 marked this pull request as ready for review June 25, 2026 19:24
@alistair3149 alistair3149 requested a review from malberts June 25, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant