Skip to content

test(G5): cross-process port-allocation race over the flock - #71

Merged
gustavobertoi merged 1 commit into
mainfrom
nightly/G5-race
Jun 29, 2026
Merged

test(G5): cross-process port-allocation race over the flock#71
gustavobertoi merged 1 commit into
mainfrom
nightly/G5-race

Conversation

@gustavobertoi

Copy link
Copy Markdown
Contributor

What

Closes G5 — the two-terminal concurrency guarantee, validated across real OS processes (subprocess-helper pattern), daemon-free and non-flaky.

How

The ledger is pre-created, then 5 copies of the test binary each allocate 6 host ports under the machine-global flock. Port allocation is the mutation that cannot be made idempotent — two processes handing out the same host port is a hard bug — so "every allocated port is distinct across every process" directly proves the cross-process flock serialized the critical section. A no-op flock would let two processes pick the same lowest-free port and collide.

Validates the repo's #1 architectural rule (lock-first concurrency) at the cross-process layer the existing internal/lock goroutine test can't reach. Verified -race -count=5.

Finding (already mitigated)

Writing this surfaced that concurrent first-open of a brand-new ledger from several processes relies on a reliable-flock filesystem (the WAL switch + migrate otherwise race) — already mitigated by doctor's 9p/networked-FS warning (fsCheck). The test pre-migrates so it isolates the allocation flock specifically.

🤖 Generated with Claude Code

Adds the two-terminal concurrency guarantee at the layer that matters, across
REAL OS processes (subprocess-helper pattern), with no daemon and no flakiness:
the ledger is pre-created, then 5 copies of the test binary each allocate 6 host
ports under the machine-global flock. Port allocation is the mutation that cannot
be made idempotent — two processes handing out the same host port is a hard bug —
so "every allocated port is distinct across every process" is a direct proof the
cross-process flock serialized the critical section. A no-op flock would let two
processes pick the same lowest-free port and collide.

Note: writing this surfaced that concurrent FIRST-open of a brand-new ledger from
several processes relies on a reliable-flock filesystem (the WAL switch + migrate
race otherwise); that hazard is already mitigated by `doctor`'s 9p/networked-FS
warning (internal/cli fsCheck). The test deliberately pre-migrates so it validates
the allocation flock specifically, independent of that.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gustavobertoi
gustavobertoi merged commit 262482d into main Jun 29, 2026
3 checks passed
@gustavobertoi
gustavobertoi deleted the nightly/G5-race branch June 29, 2026 19:50
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