Handle loader publication rename races #1539

Closed
github-bot wants to merge 3 commits from github-bot/gh-1539 into main AGit
Owner

@⁠Gauss999 on GitHub · 2026-11-28 21:23 UTC · original
Gauss999:patch-4 → main · +80 −2 · 1 files · 3 commits · closed without merging

Summary

  • Handle Windows loader publication rename races when another publisher wins: accept the existing destination only when its bytes exactly match the file being published.
  • Preserve the original rename error when the destination is missing or different, remove staging files on failure, and keep write-then-rename atomicity.
  • Add a small injection helper for deterministic loader race tests without new dependencies or cross-crate changes.
  • Conflict-resolution note: upstream main now contains the cache-side race handling and its Windows regression test. That file was adopted unchanged, leaving this PR scoped to crates/victory-loader/src/publish.rs.

Tests

  • Added loader regressions for matching destination bytes, mismatched destination bytes, and a missing destination; all verify staging cleanup and error handling.
  • The previous two-commit revision was built and tested externally on Windows: Clippy passed for victory-loader and victory-pipeline with and without all features, and the reported library test runs passed 49 + 9 tests.
  • The merge resolution was made through the GitHub web UI; no local build or tests were run on the resulting head db24ab7. CI is awaiting maintainer approval.
**@⁠Gauss999** on GitHub · 2026-11-28 21:23 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1539) `Gauss999:patch-4` → `main` · +80 −2 · 1 files · 3 commits · closed without merging ## Summary - Handle Windows loader publication rename races when another publisher wins: accept the existing destination only when its bytes exactly match the file being published. - Preserve the original rename error when the destination is missing or different, remove staging files on failure, and keep write-then-rename atomicity. - Add a small injection helper for deterministic loader race tests without new dependencies or cross-crate changes. - Conflict-resolution note: upstream `main` now contains the cache-side race handling and its Windows regression test. That file was adopted unchanged, leaving this PR scoped to `crates/victory-loader/src/publish.rs`. ## Tests - Added loader regressions for matching destination bytes, mismatched destination bytes, and a missing destination; all verify staging cleanup and error handling. - The previous two-commit revision was built and tested externally on Windows: Clippy passed for `victory-loader` and `victory-pipeline` with and without all features, and the reported library test runs passed 49 + 9 tests. - The merge resolution was made through the GitHub web UI; no local build or tests were run on the resulting head `db24ab7`. CI is awaiting maintainer approval.
Refactor file renaming logic to handle race conditions during publishing. Introduced a new function 'publish_staging' to encapsulate the renaming process and added tests for various scenarios.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 21:25:01 +00:00
Author
Owner

@⁠babuakhil on GitHub · 2026-11-28 22:03 UTC · original

Built and tested this on Windows, since it hadn't been run yet: Windows 11, Rust 1.98.1 (pinned), applied on current main (d4b5d51); both commits cherry-pick cleanly.

  • cargo clippy -p victory-loader -p victory-pipeline --all-targets --locked -- -D warnings, with and without --all-features: pass
  • the five new tests pass; cargo test -p victory-loader -p victory-pipeline --lib --locked: 49 + 9 passed, 5 of 5 runs
  • xtask policy fails only on lower.rs's size, which is already on main (#1429)

The race is real on Windows, and this fixes it. I stressed Cache::get_or_convert from a throwaway integration test (not part of this PR): 300 rounds, each with 16 threads publishing the same new entry at once while 4 threads open the destination with share_mode(FILE_SHARE_READ) (no FILE_SHARE_DELETE, as a scanner or a mapping reader would) and hold it for 200 µs. Each round also checks that no staging file is left and that the published bytes are right.

calls failed
main, run 1 4800 1570, all Access is denied. (os error 5)
main, run 2 4800 1664, same
this PR, run 1 4800 0
this PR, run 2 4800 0

With readers using std::fs::read (which shares delete), main had no failures either (0 of 14,400), so the failure needs a reader that doesn't share delete. No staging files were left on either side, and the published bytes were right every round.

The loader's write_if_changed is pub(crate), so I only covered it through this PR's unit tests, not the stress.

One design note, not a blocker: the cache accepts any regular file at the destination after a failed rename, while the loader requires its exact bytes. That seems right given the key is a content hash; the PR says readers validate on decode, which I didn't check. Happy to share the stress test if it's useful.

**@⁠babuakhil** on GitHub · 2026-11-28 22:03 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1539#issuecomment-7246465964) Built and tested this on Windows, since it hadn't been run yet: Windows 11, Rust 1.98.1 (pinned), applied on current `main` (`d4b5d51`); both commits cherry-pick cleanly. - `cargo clippy -p victory-loader -p victory-pipeline --all-targets --locked -- -D warnings`, with and without `--all-features`: pass - the five new tests pass; `cargo test -p victory-loader -p victory-pipeline --lib --locked`: 49 + 9 passed, 5 of 5 runs - `xtask policy` fails only on `lower.rs`'s size, which is already on `main` (#1429) **The race is real on Windows, and this fixes it.** I stressed `Cache::get_or_convert` from a throwaway integration test (not part of this PR): 300 rounds, each with 16 threads publishing the same new entry at once while 4 threads open the destination with `share_mode(FILE_SHARE_READ)` (no `FILE_SHARE_DELETE`, as a scanner or a mapping reader would) and hold it for 200 µs. Each round also checks that no staging file is left and that the published bytes are right. | | calls | failed | |---|---:|---:| | `main`, run 1 | 4800 | 1570, all `Access is denied. (os error 5)` | | `main`, run 2 | 4800 | 1664, same | | this PR, run 1 | 4800 | 0 | | this PR, run 2 | 4800 | 0 | With readers using `std::fs::read` (which shares delete), `main` had no failures either (0 of 14,400), so the failure needs a reader that doesn't share delete. No staging files were left on either side, and the published bytes were right every round. The loader's `write_if_changed` is `pub(crate)`, so I only covered it through this PR's unit tests, not the stress. One design note, not a blocker: the cache accepts any regular file at the destination after a failed rename, while the loader requires its exact bytes. That seems right given the key is a content hash; the PR says readers validate on decode, which I didn't check. Happy to share the stress test if it's useful.
github-bot changed title from Handle concurrent publication rename races to Handle loader publication rename races 2026-11-29 05:09:04 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-11-29 08:28 UTC · original

Thank you! An earlier version of this pull request was merged into main with its original commits and is part of v2026.11.29.01, where you are credited. GitHub does not show it as merged because new commits were pushed here after that merge. It stays open so those newer commits can be looked at next.

**@⁠trustno1-coder** on GitHub · 2026-11-29 08:28 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1539#issuecomment-7253124987) Thank you! An earlier version of this pull request was merged into main with its original commits and is part of [v2026.11.29.01](https://github.com/trustno1-coder/VIctory-NVIDIA/releases/tag/v2026.11.29.01), where you are credited. GitHub does not show it as merged because new commits were pushed here after that merge. It stays open so those newer commits can be looked at next.
github-bot closed this pull request 2026-11-29 18:34:55 +00:00
Author
Owner

@⁠Gauss999 on GitHub · 2026-11-29 18:34 UTC · original

Closing this after auditing the current heads: there is no residual behaviour left in this PR. The diff of crates/victory-loader/src/publish.rs against the current upstream/main is empty — the original commits are integrated upstream (0c07d4ac, part of v2026.11.29.01, with authorship credit as noted above), and the branch only carries the merge commit db24ab7e on top. Nothing further to review here; thanks for keeping the credit intact.

**@⁠Gauss999** on GitHub · 2026-11-29 18:34 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1539#issuecomment-7260585861) Closing this after auditing the current heads: there is no residual behaviour left in this PR. The diff of crates/victory-loader/src/publish.rs against the current upstream/main is empty — the original commits are integrated upstream (0c07d4ac, part of v2026.11.29.01, with authorship credit as noted above), and the branch only carries the merge commit db24ab7e on top. Nothing further to review here; thanks for keeping the credit intact.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!1539
No description provided.