Repository navigation
GPU: serialize pipeline library saves and use unique temp files - #164
HailLucifer666 wants to merge 2 commits into
Conversation
|
I reproduced a save-retry problem on this head ( An independent retry patch on this head passed eight source-built cases. These cover real rename failures, retrying the early list independently after successful host publication, injected serialize and staging failures, successful fallback, and Stores or early notes arriving during publication. The patch acknowledges the serialized Store count only after a successful rename and subtracts that snapshot so new Stores stay pending. It also restores the early-list dirty flag if its write fails. The repro uses real filesystem operations with a simulated D3D12 library. Native D3D12 and concurrent processes sharing the same cache were outside this run. This retry behavior can be tested independently of the startup ordering change in #211. |
…line library saves and use unique temp files Part of #16 # Conflicts: # crates/victory-gpu/src/pipeline/library.rs
|
Independent verification: PR #535 does not exist on this repo (redirects to issue #535). Verified PR #164 (GPU: serialize pipeline library saves and use unique temp files) instead, which matches the description of fixing a race in the pipeline library cache. Build: success. PR-specific tests: 6/6 passed including the 2 new concurrent safety tests (concurrent_write_atomically_never_fails_or_leaves_temp_files, concurrent_save_io_and_replace_library_never_collide_or_leak_tmp). Full workspace tests timed out after 480s (expected for cross-compilation through Wine). No merge conflicts. Machine: Arch Linux, kernel 7.3.5-arch1-1, 3x RTX 4090 driver 620.73.04, Proton, AI-assisted. |
THE BUG. save() staged the pipeline library to a fixed host-pipelines.tmp path and dropped library.saving.write() before calling replace_library(), while write_atomically() staged early-pipelines.txt to a fixed .tmp path with no lock. WHY NOT HYPOTHETICAL. Periodic 20 s worker saves and shutdown save(true) can overlap on Windows, causing a concurrent thread to truncate or overwrite the staging file while another thread renames it over the mapped library or early list. THE FIX. Serialize on-disk staging and replacement under SAVE_IO (without extending library.saving.write() across renames), generate unique .tmp-<pid>-<seq> staging paths via unique_tmp() for both save() and write_atomically(), and remove the temp file on rename failure. SCOPE. Only pipeline/library.rs on-disk staging and replacement. Pipeline compilation, mapping, and cache format are unchanged.
…o write THE BUG. save() cleared both dirty flags before either write landed: it stored 0 into the library's added count before replace_library() renamed the serialised bytes into place, and it cleared the early list's changed flag before write_atomically() wrote that list. When a rename failed (the target held by a folder, the file held open, a system refusing to replace a mapped file), the retry found nothing dirty and returned: the pipelines this run had added, and the title pipelines it had noted for an early start, were lost with the process. WHY NOT HYPOTHETICAL. avt0m4t48 reproduced it on baf1154 and on main (2119b0e): with the obstruction removed, a second save(true) returned without writing the pending data. Both destinations replace_library() tries have to fail for the library to be lost, but the early list is one write and fails on its own. THE FIX. publish() puts the library and the early list in place and clears the dirty state for exactly what reached the disk: the added count is acknowledged with fetch_sub(snapshot) only after the rename succeeds, so stores that arrived while the library was being serialised stay pending, and a write that did not land sets the early list's flag again. A serialise failure restores it too. SCOPE. The rest of the save path is unchanged: the same lock, the same unique staging file, the same order. The startup ordering change in fxceless#211 is not part of this. Three tests, three probes: acknowledging the stores before the rename, clearing every store instead of the snapshot, and dropping the early-list restore each fail the test named for it. Co-authored-by: avt0m4t48 <avt0m4t48@users.noreply.github.com>
baf1154 to
f3230ff
Compare
|
Thank you — this reproduced exactly as you described, and the fix follows the shape of your patch. What was wrong. What changed (
Tests — three, new, all with real filesystem operations against a simulated library, as in your repro:
Each was checked against the bug: acknowledging the stores before the rename, clearing every store instead of the snapshot, and dropping the early-list restore each fail the test named for it. The probes are recorded in the test file so the next editor has them. Gate, on this head rebased onto Not covered, the same as your run: native D3D12 and concurrent processes sharing one cache. No local title files here, so it is the same simulated-library shape you used. Rebased onto |
|
Your repro is addressed on
So the failure path leaves the store count untouched and the early list dirty, and the next Tests, one per requirement — none of these existed before:
Probe: acknowledge the stores before checking the rename result — the shape of the original bug — and all three fail, the first with
Two things I did not cover, so they are not read as covered: native D3D12 — the tests use a simulated library, as you noted — and two processes sharing one cache directory. Both are outside what this repo can run here. If you have a machine where the obstruction is real (a mapped file the system refuses to replace), that is the run that would settle |
…less/victory-fork#164) (cherry picked from commit 79c97321b45bf2d3635eb4e48280df3fcb5cf1b8)
Problem
save()staged the pipeline library to a fixedhost-pipelines.tmppath and releasedlibrary.saving.write()before callingreplace_library().write_atomically()stagedearly-pipelines.txtto a fixed.tmppath with no lock.save(true)can race on the same temp file or leave stale temp files on rename error.Fix
SAVE_IOwithout holdinglibrary.saving.write()across renames..tmp-<pid>-<seq>staging paths viaunique_tmp()for bothsave()andwrite_atomically().replace_library()andwrite_atomically().Verification
write_atomicallyandSAVE_IO+replace_libraryverifying integrity and zero leftover.tmp-*files.cargo clippy --workspace --all-targets --locked -- -D warningscargo clippy --workspace --all-targets --all-features --locked -- -D warningscargo test -p victory-gpu pipeline::library::tests --locked(6/6 passed)cargo test -p xtask --locked(4/4 passed)