GPU: serialize pipeline library atomic writes with unique temp files #1659

Merged
HailLucifer666 merged 1 commit from upstream-pr/1660 into main 2026-11-25 00:15:07 +00:00
HailLucifer666 commented 2026-11-24 20:33:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by HailLucifer666 on 2026-11-24T20:33:34Z.


Issue:
pipeline::library::save releases both LAST and library locks before calling write_atomically, which always wrote to the same fixed host-pipelines.tmp path. Concurrent pipeline worker saves and shutdown save(true) can truncate or unlink each other's temp file on Windows, failing or corrupting the saved pipeline library.

Fix:

  • Serialize write_atomically with a mutex, write to a unique per-call temp file (.tmp-<pid>-<n>), and clean up the temp file if rename fails.
  • Added 4-thread concurrent stress test concurrent_write_atomically_never_fails_or_truncates.

Verification:

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (clean)
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings (clean)
  • cargo test -p victory-gpu --locked (51 passed, 0 failed, 1 ignored)
  • cargo test -p xtask --locked (4 passed, 0 failed)
  • No game files used.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6590862635 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1660). Originally posted by [HailLucifer666](https://github.com/HailLucifer666) on 2026-11-24T20:33:34Z. --- **Issue:** `pipeline::library::save` releases both `LAST` and `library` locks before calling `write_atomically`, which always wrote to the same fixed `host-pipelines.tmp` path. Concurrent pipeline worker saves and shutdown `save(true)` can truncate or unlink each other's temp file on Windows, failing or corrupting the saved pipeline library. **Fix:** - Serialize `write_atomically` with a mutex, write to a unique per-call temp file (`.tmp-<pid>-<n>`), and clean up the temp file if `rename` fails. - Added 4-thread concurrent stress test `concurrent_write_atomically_never_fails_or_truncates`. **Verification:** - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` (clean) - `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings` (clean) - `cargo test -p victory-gpu --locked` (51 passed, 0 failed, 1 ignored) - `cargo test -p xtask --locked` (4 passed, 0 failed) - No game files used.
catminou4 commented 2026-11-24 23:04:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T22:19:51Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Pipeline library atomic writes serialized: concurrent worker and shutdown saves no longer race on the same staging file or target rename. concurrent_write_atomically_never_fails_or_truncates covers it.

<!-- greyfinch-sync:Marvisak/VIctory:review:6048311269 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1660#pullrequestreview-6048311269). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T22:19:51Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Pipeline library atomic writes serialized: concurrent worker and shutdown saves no longer race on the same staging file or target rename. concurrent_write_atomically_never_fails_or_truncates covers it.
acetonahard-code commented 2026-11-24 23:05:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by acetonahard-code on 2026-11-24T22:11:39Z.


Overlap: #72 already serializes pipeline-library saves and writes each publication to a unique temporary file. That's a superset of this change. The two conflict in library.rs.

Tested on Windows 11, RTX 4070 SUPER (driver 621.14), with the repo toolchain, merged into current main (70564ae):

cargo test -p victory-gpu passed failed ignored
main 76 2 1
main + this PR 77 2 1
main, --all-features 79 2 -
main + this PR, --all-features 80 2 -
  • The new test passes.
  • No GPU test skipped for lack of a device.
  • cargo clippy --all-targets -- -D warnings, with and without --all-features: clean.
  • Two victory-gpu tests fail on current main on this NVIDIA card: dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views. That's the 1,000,000-view heap cap, see #1744. They fail the same way with this PR, and no other test does.

I didn't test with game data.


Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145923897 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1660#issuecomment-7145923897). Originally posted by [acetonahard-code](https://github.com/acetonahard-code) on 2026-11-24T22:11:39Z. --- Overlap: #72 already serializes pipeline-library saves and writes each publication to a unique temporary file. That's a superset of this change. The two conflict in `library.rs`. Tested on Windows 11, RTX 4070 SUPER (driver 621.14), with the repo toolchain, merged into current `main` (70564ae): | `cargo test -p victory-gpu` | passed | failed | ignored | |---|---|---|---| | `main` | 76 | 2 | 1 | | `main` + this PR | 77 | 2 | 1 | | `main`, `--all-features` | 79 | 2 | - | | `main` + this PR, `--all-features` | 80 | 2 | - | - The new test passes. - No GPU test skipped for lack of a device. - `cargo clippy --all-targets -- -D warnings`, with and without `--all-features`: clean. - Two `victory-gpu` tests fail on current `main` on this NVIDIA card: `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`. That's the 1,000,000-view heap cap, see #1744. They fail the same way with this PR, and no other test does. I didn't test with game data. --- <sub>Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.</sub>
upstream-sync closed this pull request 2026-11-25 01:06:59 +00:00
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!1659
No description provided.