Loader: accept identical destination when concurrent publish rename fails #2795

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/2797 into main
fuzeofficlal commented 2026-11-25 20:47:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T20:47:52Z.


What

publish::write_if_changed now treats a failed std::fs::rename(&staging, path) as success if path already holds the exact bytes being published (after removing the staging file), and also removes the staging file on a failed std::fs::write.

Why

victory_loader::load calls publish::write_if_changed(&path, &prepared.bytes) and immediately maps path with LoadLibraryExW, which opens the file without FILE_SHARE_DELETE on Windows. When two runners prepare the same image into a shared cache directory concurrently, both can miss the initial std::fs::read(path) fast path, write distinct staging files, and race on std::fs::rename. Once the winner renames and maps path, the loser's rename fails with PermissionDenied / sharing violation even though path already contains the identical prepared image.

If path holds different bytes (or cannot be read), the original rename error is still returned after removing the staging file.

Verification

  • cargo test --locked -p victory-loader: 36 passed, 0 failed (including two deterministic Windows FILE_SHARE_READ-locked tests covering both identical and differing destination contents).
  • cargo clippy --locked -p victory-loader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 184 files ok.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6613449084 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2797). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T20:47:52Z. --- ## What `publish::write_if_changed` now treats a failed `std::fs::rename(&staging, path)` as success if `path` already holds the exact `bytes` being published (after removing the staging file), and also removes the staging file on a failed `std::fs::write`. ## Why `victory_loader::load` calls `publish::write_if_changed(&path, &prepared.bytes)` and immediately maps `path` with `LoadLibraryExW`, which opens the file without `FILE_SHARE_DELETE` on Windows. When two runners prepare the same image into a shared cache directory concurrently, both can miss the initial `std::fs::read(path)` fast path, write distinct staging files, and race on `std::fs::rename`. Once the winner renames and maps `path`, the loser's `rename` fails with `PermissionDenied` / sharing violation even though `path` already contains the identical prepared image. If `path` holds *different* bytes (or cannot be read), the original rename error is still returned after removing the staging file. ## Verification - `cargo test --locked -p victory-loader`: **36 passed, 0 failed** (including two deterministic Windows `FILE_SHARE_READ`-locked tests covering both identical and differing destination contents). - `cargo clippy --locked -p victory-loader --all-targets -- -D warnings`: **0 warnings**. - `cargo xtask policy`: **184 files ok**.
kotekompotek commented 2026-11-25 22:04:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T21:14:32Z.

Review: COMMENTED


Correct fix for the Windows rename semantics: fs::rename over a destination opened without FILE_SHARE_DELETE fails, and when several runners publish the same title image the loser's rename can fail after the winner already wrote identical bytes. Comparing the destination to the staged bytes on failure turns exactly the 'someone else published the same bytes' case into a no-op success, and returns the original error otherwise. Tests lock the destination with read-share only, which reproduces the rename failure deterministically. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6065075528 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2797#pullrequestreview-6065075528). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T21:14:32Z. **Review:** COMMENTED --- Correct fix for the Windows rename semantics: `fs::rename` over a destination opened without `FILE_SHARE_DELETE` fails, and when several runners publish the same title image the loser's rename can fail after the winner already wrote identical bytes. Comparing the destination to the staged bytes on failure turns exactly the 'someone else published the same bytes' case into a no-op success, and returns the original error otherwise. Tests lock the destination with read-share only, which reproduces the rename failure deterministically. LGTM.
Marvisak commented 2026-11-26 00:03:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:23:07Z.


Automated triage for the maintainers.

In publish::write_if_changed (crates/victory-loader/src/publish.rs), this PR treats a failed rename as success when the destination already holds the same bytes (new publish_staged). It also removes the staging file when the write itself fails. The race is real: windows.rs maps the published image with LoadLibraryExW straight after publishing, and Windows will not rename over a mapped image. A different or unreadable destination still returns the original error. The two new Windows tests lock the destination without delete sharing. CI passes.

Minor: the PR also reflows an unrelated assert! in the existing test, and the module doc no longer mentions renaming over another writer's file.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177486525 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2797#issuecomment-7177486525). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:23:07Z. --- <!-- victory-triage v1 head=ea27d8e29dad7f2a291888935b797c8ab9b1a1b0 verdict=merge-candidate at=2026-11-25T23:23:01Z --> Automated triage for the maintainers. In `publish::write_if_changed` (`crates/victory-loader/src/publish.rs`), this PR treats a failed rename as success when the destination already holds the same bytes (new `publish_staged`). It also removes the staging file when the write itself fails. The race is real: `windows.rs` maps the published image with `LoadLibraryExW` straight after publishing, and Windows will not rename over a mapped image. A different or unreadable destination still returns the original error. The two new Windows tests lock the destination without delete sharing. CI passes. Minor: the PR also reflows an unrelated `assert!` in the existing test, and the module doc no longer mentions renaming over another writer's file. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
futurepro62 commented 2026-11-26 02:06:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T01:12:48Z.


Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head ea27d8e (on its base 13f91ca).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 775 passed, 0 failed, 9 ignored.
  • The new tests ran and passed: concurrent_rename_accepts_identical_locked_destination, failed_rename_with_different_locked_destination_still_errors.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7179546051 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2797#issuecomment-7179546051). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T01:12:48Z. --- Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `ea27d8e` (on its base `13f91ca`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **775 passed, 0 failed, 9 ignored**. - The new tests ran and passed: `concurrent_rename_accepts_identical_locked_destination`, `failed_rename_with_different_locked_destination_still_errors`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Dukestar69 commented 2026-11-26 04:05:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T03:12:59Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64:

  • cargo test -p victory-loader --lib publish::tests: 4 passed, 0 failed (including new concurrent_rename_accepts_identical_locked_destination and failed_rename_with_different_locked_destination_still_errors).
  • cargo clippy -p victory-loader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6068053605 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2797#pullrequestreview-6068053605). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T03:12:59Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - `cargo test -p victory-loader --lib publish::tests`: **4 passed, 0 failed** (including new `concurrent_rename_accepts_identical_locked_destination` and `failed_rename_with_different_locked_destination_still_errors`). - `cargo clippy -p victory-loader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2797:upstream-pr/2797'
git switch 'upstream-pr/2797'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2797'
git switch 'upstream-pr/2797'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2797'
git switch 'upstream-pr/2797'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2797'
git switch 'main'
git merge --squash 'upstream-pr/2797'
git switch 'main'
git merge --ff-only 'upstream-pr/2797'
git switch 'main'
git merge 'upstream-pr/2797'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2795
No description provided.