Skip to content

test: give fast_io copy_file_range temp files pid-unique names - #8139

Merged
oferchen merged 1 commit into
masterfrom
fix/fastio-copy-range-test-handle-race
Oct 8, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/fastio-copy-range-test-handle-race

Conversation

@oferchen

@oferchen oferchen commented Oct 8, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes an intermittent Windows failure in fast_io copy_file_range::tests::test_copy_partial_eof. Run 37709885081 failed with NamedTempFile::new() returning PathError { path: ...\Temp\.tmpSxD9oN, os error 5 }. It failed in about 1 of 40 runs.

Root cause

The test fails while creating a new temp file, not while using a handle afterwards.

  • Same seed in every test process: nextest runs each test in its own process. On non-wasm targets, fastrand 2.4.1 (global_rng.rs random_seed) seeds the temp-name generator from Instant::now() and the thread id only. The test thread id is the same in every process, so two processes seeded in the same clock tick generate the same .tmpXXXXXX names.
  • No retry on that error: on Windows, creating a file over another process's temp directory or delete-pending file of the same name returns PermissionDenied. tempfile 3.27.0 (util.rs create_helper) retries only AlreadyExists and AddrInUse, so the error reaches the test as a panic.

Fix

This is a test-only change. Every temp file in the module is now created through new_temp_file(), which puts .tmp<pid>- at the front of the name. Two live processes always have different pids, so their names can no longer collide. The - also keeps these names apart from tempfile's purely alphanumeric default names.

All 15 call sites are converted. There are no retries, sleeps, #[ignore]s or Windows skips.

Verification

  • Linux: cargo nextest run -p fast_io --all-features -E 'test(copy_file_range)' ran 12 tests, all passing. strace shows the new names, for example /tmp/.tmp2865819-zMpeYY.
  • Windows: the x86_64-pc-windows-gnu cross type-check is clean, as are clippy and fmt.
  • Not yet verified: the Windows test run itself is only covered by this PR's CI. At about 1 failure in 40, one green run proves little.

Follow-up (not in this PR)

About 49 files in crates/fast_io/src call NamedTempFile::new(), tempdir() or TempDir::new() and are exposed to the same collision on Windows. The fix there is a shared test-support helper; that will be its own change.

nextest runs each test in its own process and tempfile seeds its name
generator from the clock and thread id only, so concurrent test
processes can draw the same .tmpXXXXXX name. On Windows a clash with
another process's directory or delete-pending file fails with
PermissionDenied, which tempfile does not retry, so
test_copy_partial_eof failed once in the IOCP job.

Create every temp file in the module through a helper that prefixes
the name with the process id, so names from live processes are
disjoint.
@oferchen
oferchen enabled auto-merge (squash) October 8, 2026 08:53
@github-actions github-actions Bot added the test label Oct 8, 2026
@oferchen
oferchen merged commit 7bc2964 into master Oct 8, 2026
80 checks passed
@oferchen
oferchen deleted the fix/fastio-copy-range-test-handle-race branch October 8, 2026 11:24
mevanlc pushed a commit to mevanlc/rsync-rs that referenced this pull request Oct 14, 2026
…chen#8139)

nextest runs each test in its own process and tempfile seeds its name
generator from the clock and thread id only, so concurrent test
processes can draw the same .tmpXXXXXX name. On Windows a clash with
another process's directory or delete-pending file fails with
PermissionDenied, which tempfile does not retry, so
test_copy_partial_eof failed once in the IOCP job.

Create every temp file in the module through a helper that prefixes
the name with the process id, so names from live processes are
disjoint.
oferchen added a commit that referenced this pull request Nov 15, 2026
…rd-link detection (#277) (#8387)

## Summary
- **#311 (`crates/platform/src/signal.rs`):** Factor Windows console
control event dispatch out of the `unsafe extern "system" fn handler`
into `dispatch_console_ctrl(ctrl_type, shutdown, graceful) -> bool` with
compile-time `const` assertions against Win32 `CTRL_*_EVENT` constants
and cross-platform unit tests.
- **#277 (`crates/fast_io/src/same_fs.rs`,
`crates/engine/src/local_copy/hard_links/windows.rs`,
`crates/engine/src/local_copy/executor/file/copy/links.rs`):**
- Add `fast_io::same_fs::FileIdentity` and `file_identity(path)` sharing
a single `windows_file_info` (`GetFileInformationByHandle`) helper on
Windows and `symlink_metadata` on Unix.
- Implement Windows `HardLinkTracker` (`existing_target_for_path` /
`record_for_path`) keyed by `(volume_id, file_index)` when `nlink > 1`,
and wire `source` at local-copy call sites.
- Implement `is_already_hardlinked(destination, target)` via
`fast_io::same_fs::file_identity` on both Unix and Windows.
- Note from audit: **#407** (`test_copy_partial_eof` temp-file
pid-unique naming) was already fixed in `7bc2964a4` (#8139), and
**#353** (required Windows CI full workspace test surface) landed in
`c88299623` (#8316).

## Verification
- `cargo fmt --all -- --check`
- `cargo test --locked -p platform`: 88 passed, 0 failed
- `cargo test --locked -p fast_io --lib same_fs`: 6 passed, 0 failed
(1111 filtered out)
- `cargo test --locked -p engine --lib local_copy::hard_links`: 50
passed, 0 failed (4559 filtered out)
- `cargo clippy --locked -p platform -p fast_io -p engine --all-targets
-- -D warnings`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant