Skip to content

fix(coreutils): give each shim_dir call its own staging dir - #523

Merged
raphaelvigee merged 1 commit into
masterfrom
raphaelvigee/fix-coreutils-staging-race
Oct 29, 2026
Merged

raphaelvigee merged 1 commit into
masterfrom
raphaelvigee/fix-coreutils-staging-race

Conversation

@raphaelvigee

Copy link
Copy Markdown
Member

Problem

A cold start of the builtin coreutils shim dir can fail with Directory not empty. It also happens on master. shim_dir staged into .tmp-<pid>-<name>, a name that is unique per process but not per call. Concurrent targets in one heph all reach a cold shim dir at once and share that dir. One caller's "clear stale staging" remove_dir_all races another caller's symlink writes.

Fix

Add a process-wide AtomicU64 sequence to the staging name: .tmp-<pid>-<seq>-<name>. Each call now stages alone. The publish step (rename into place, where the loser of a race checks that the winner's dir exists) was already safe and is unchanged.

Test

shim_dir_survives_concurrent_cold_start_in_one_process: 16 threads behind a barrier call shim_dir on a fresh home, repeated 20 times. Every thread must get a complete shim set.

Run against the unfixed code, it fails (same race, sibling symptom):

called `Result::unwrap()` on an `Err` value: link coreutils shim "base64" -> ".../heph"
Caused by:
    File exists (os error 17)

With the fix it passes, and still passed on 3 reruns. cargo test -p coreutils and lint pass.

🤖 Generated with Claude Code

The staging dir was named `.tmp-<pid>-<name>`, so concurrent targets in
one heph process that all hit a cold shim dir shared it. One caller's
stale-dir `remove_dir_all` raced another's symlink writes and failed
with "Directory not empty" (or "File exists" on the symlink). Add a
process-wide counter to the name so each call stages alone. The rename
into place already loses a race harmlessly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@raphaelvigee
raphaelvigee enabled auto-merge (squash) October 29, 2026 16:17
@raphaelvigee
raphaelvigee merged commit d11d66e into master Oct 29, 2026
23 checks passed
@raphaelvigee
raphaelvigee deleted the raphaelvigee/fix-coreutils-staging-race branch October 29, 2026 16:55
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