Skip to content

Fix race when parallel workers copy static assets - #1178

Merged
sferik merged 1 commit into
mainfrom
fix-static-asset-copy-race
May 4, 2026
Merged

sferik merged 1 commit into
mainfrom
fix-static-asset-copy-race

Conversation

@sferik

@sferik sferik commented May 4, 2026 •

Copy link
Copy Markdown
Collaborator

The parallel_tests.feature cucumber scenarios fail intermittently on a clean main with Errno::ENOENT from inside HTMLFormatter#copy_static_assets. Reproducible locally, ~2 of 5 scenarios fail per run.

When parallel rspec workers exit at roughly the same time, each one runs the formatter against the shared coverage directory. FileUtils.cp_r(path, dest_dir, remove_destination: true) performs an unlink-then-copy, and one process ends up unlinking an asset (e.g. favicon_red.png) just before another process also tries to unlink it.

Switched to per-file copy via a uniquely-named temp file in the destination directory followed by File.rename. Rename is atomic and overwrite-safe on POSIX, so two writers landing on the same path no longer race; whichever finishes last wins, and the file is always coherent. The public/ directory is flat so we don't lose anything by walking files individually instead of using cp_r.

When parallel test workers exit at roughly the same time, each one
calls HTMLFormatter#copy_static_assets against the shared coverage
directory. cp_r with remove_destination: true would have one process
unlink an asset (e.g. favicon_red.png) just before another process
also tried to unlink it, raising Errno::ENOENT.

Copy each file via a uniquely-named temp file in the destination
directory and then File.rename onto the final path. rename is atomic
on POSIX and overwrite-safe, so concurrent writers can no longer
race on the same path.
@sferik
sferik force-pushed the fix-static-asset-copy-race branch from d57ca84 to dfc48da Compare May 4, 2026 21:59
@sferik
sferik merged commit 69c2235 into main May 4, 2026
24 checks passed
@sferik
sferik deleted the fix-static-asset-copy-race branch August 12, 2026 19:51
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