GPU: serialize pipeline library saves and use unique temp files #164
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!164
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-164"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@HailLucifer666 on GitHub · 2026-11-24 22:06 UTC · original
HailLucifer666:fix/pipeline-library-save-race→main· +236 −24 · 1 files · 2 commits · openProblem
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)@avt0m4t48 on GitHub · 2026-11-24 22:58 UTC · original
I reproduced a save-retry problem on this head (
baf1154) and current main (2119b0e). When an early-list rename fails, or both host-library rename destinations fail,save(true)can clear the dirty state before publication succeeds. After removing the filesystem obstruction, a secondsave(true)can return without writing the previously pending data. The same problem is present on #211.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.
@Headache3318 on GitHub · 2026-11-25 09:24 UTC · original
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.
@HailLucifer666 on GitHub · 2026-11-25 09:44 UTC · original
Thank you — this reproduced exactly as you described, and the fix follows the shape of your patch.
What was wrong.
save()cleared both dirty flags before either write landed: it stored0into the library'saddedcount beforereplace_library()renamed the serialised bytes into place, and it cleared the early list'schangedflag beforewrite_atomically()wrote that list. A failed rename therefore left the retry with nothing to do. Both destinations have to fail for the library to be lost, but the early list is one write and fails on its own — including when the library write fails first and the list is never attempted.What changed (
crates/victory-gpu/src/pipeline/library.rs). The publication step is nowpublish():added.fetch_sub(snapshot, Relaxed)only afterreplace_library()returnsOk(()), so stores that arrive while the library is being serialised stay pending for the next save.serialise()failure restores the early-list flag too; that path used to drop the pending early list as well.Tests — three, new, all with real filesystem operations against a simulated library, as in your repro:
a_save_whose_rename_fails_keeps_its_stores_and_early_list_pending— both rename destinations held by a folder (ERROR_ACCESS_DENIED), then released: the retry writes both files.a_save_acknowledges_only_the_stores_it_serialised— a store arriving between the snapshot and the publication stays pending.an_early_list_that_cannot_be_written_stays_pending_after_the_library_is_published— the library lands, the list does not, and only the list stays dirty.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
9376fd60:pipeline::library::tests9 passed;cargo test -p victory-gpu149 passed, 3 ignored;cargo test -p xtask4 passed. Both clippy passes are red in this workspace for three pre-existing diagnostics that are identical onmainat9376fd60(placed_filler_twinsnever used,sort_unstable_by_keyindraw.rs,depth_writtennever read) —main's own CI Clippy job failed at that commit. This branch adds none of them; I left them alone rather than widen the diff.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
9376fd60and force-pushed with lease.@HailLucifer666 on GitHub · 2026-11-25 13:49 UTC · original
Your repro is addressed on
f3230ff5, and I want to be precise about which of your requirements each part answers, because the ordering is the whole fix.publish()now does, in this order:replace_library— the rename, or the fallback that leaves the new file beside the old one.Ok:added.fetch_sub(snapshot), wheresnapshotis the count taken before serialisation began. That is your "acknowledge the serialized Store count only after a successful rename".snapshot, so they survive the subtraction and the next save writes them.changedis set back totrue.So the failure path leaves the store count untouched and the early list dirty, and the next
save(true)writes the data instead of returning early. That is the bug you described atbaf1154.Tests, one per requirement — none of these existed before:
a_save_acknowledges_only_the_stores_it_serialiseda_save_whose_rename_fails_keeps_its_stores_and_early_list_pendingan_early_list_that_cannot_be_written_stays_pending_after_the_library_is_publishedProbe: acknowledge the stores before checking the rename result — the shape of the original bug — and all three fail, the first with
the store that arrived during the save is still pending(count-3, i.e. an underflow past zero, which is what acknowledges-what-never-wrote looks like). Restored byte-identical afterwards.cargo test -p victory-gpu --lib pipeline::library: 9 passed, 0 failed.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
replace_library's fallback path rather than its error path.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.