Skip to content

test(broker-v2): race N concurrent starters, assert exactly one singleton survivor (soldr#2361 Phase 1) - #899

Merged
zackees merged 2 commits into
mainfrom
test/2363-singleton-race-2361
Aug 8, 2026
Merged

zackees merged 2 commits into
mainfrom
test/2363-singleton-race-2361

Conversation

@zackees

@zackees zackees commented Aug 8, 2026

Copy link
Copy Markdown
Owner

What this is

Closes a testing gap for zackees/soldr#2361 Phase 1 / soldr#2363: the single-instance (singleton-per-user-session) enforcement in running-process-broker-v2::main already existed — bind failure classified via is_already_bound_error refuses startup with EX_TEMPFAIL (75) — but only the error-classification helper had unit tests. #2363's testing invariants ask for it to be race-tested (N concurrent starters → exactly one survivor), which this PR adds.

What it does

Spawns 5 real running-process-broker-v2 child processes concurrently with the same --program name (same user session), then classifies each by whether it printed bound at on stdout (winner) or exited EX_TEMPFAIL(75) (loser). Asserts exactly 1 winner and 4 losers.

No cfg gate: the bind/refuse code path in main() is identical on every platform (interprocess crate abstracts Windows named pipes vs. unix sockets underneath), so this runs against the host's real transport everywhere.

Stable across 4 repeated local runs (Windows).

Testing

soldr cargo test -p running-process --test broker_v2_scaffold_accepts_connection --features client
# 6 passed; 0 failed (5 pre-existing + this one)
soldr cargo fmt -p running-process
soldr cargo clippy -p running-process --test broker_v2_scaffold_accepts_connection --features client -- -D warnings

…eton survivor

Closes the gap between the existing is_already_bound_error unit tests
(error-classification only) and soldr#2363's testing invariant: N
concurrent broker-v2 starters on the same program/user must yield
exactly one bound survivor, with every other starter exiting
EX_TEMPFAIL (75) cleanly. Runs against the host's real transport (named
pipes on Windows, unix sockets elsewhere) with no cfg gate needed --
the bind/refuse code path in main() is identical on every platform.
Stable across repeated local runs.

The single-instance enforcement itself already existed in
running-process-broker-v2::main; this only adds the missing
process-level race test.

Co-Authored-By: Claude Fable 5 <[email protected]>
…ket on startup

CI on running-process#899 caught the real bug the new singleton race
test was written to catch: 5 concurrent broker-v2 starters on Linux all
reported 'bound at' and the test's own assertion (exactly one survivor)
failed with left=5, right=1.

Root cause: on Unix, main() unconditionally ran
'let _ = std::fs::remove_file(&socket_path);' before every bind
attempt, regardless of whether the path was actually stale (orphaned by
a crashed process) or live (another starter's active listener). Under a
real concurrent-start race each of the N starters, in turn, deleted the
current winner's live socket file out from under it and rebound over
the freed path -- so every starter observed a successful bind.

Fix: never unlink up front. Attempt bind first. Only on an
already-bound-classified failure, connect-probe the path
(unix_socket_path_is_stale): ConnectionRefused/NotFound means orphaned
and safe to remove + retry once; a successful connect (or anything
else) means a live peer owns it, so leave it alone and report the
already-bound refusal as before. Windows is unaffected -- the named
pipe namespace is kernel-managed and was never touched by this cleanup
step.

Also bumps platform_compliance_baseline.toml's RP-RAW-STDIO-014 debt
allowance for broker_v2_scaffold_accepts_connection.rs (9 -> 11) to
cover the 2 new Stdio uses in the singleton race test the guard flagged
on the same CI run.

Co-Authored-By: Claude Fable 5 <[email protected]>
@zackees

zackees commented Aug 8, 2026

Copy link
Copy Markdown
Owner Author

The concurrent-starter race test (this PR) caught a real bug on Linux/macOS/musl CI, not test flakiness: all 5 starters reported bound at — assertion left == right failed: exactly one starter must win the bind race / left: 5, right: 1.

Root cause: main()'s Unix stale-file cleanup ran std::fs::remove_file(&socket_path) unconditionally before every bind attempt, with no check for whether the path was actually stale or another starter's live listener. Under a real race, each starter in turn deleted the current winner's live socket and rebound over it — so all N "won" sequentially.

Fixed in the latest commit: bind is attempted first with no pre-emptive unlink; only on an already-bound failure does a connect-probe (unix_socket_path_is_stale) distinguish orphaned (ConnectionRefused/NotFound → safe to remove + retry once) from live (leave alone, report already-bound as before). Also bumped the platform_compliance_baseline.toml Stdio debt allowance the async-compliance guard flagged on the same run.

Windows is unaffected — the named pipe namespace never had this cleanup step.

@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.11111% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...nning-process/src/bin/running-process-broker-v2.rs 61.11% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

@zackees
zackees merged commit 8b8583b into main Aug 8, 2026
15 checks passed
@zackees
zackees deleted the test/2363-singleton-race-2361 branch August 8, 2026 09:36
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