GPU/pipeline/library: serialize save() file writes/renames and use unique temp paths #566
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/566"
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?
Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T02:17:23Z.
Problem
In
crates/victory-gpu/src/pipeline/library.rs, multiple background pipeline worker threads calllibrary::save(false)while shutdown callslibrary::save(true)(bypassing the 20 sSAVE_EVERYgate).save()releasedlibrary.saving.write()immediately afterserialise(), before callingreplace_library(dir, &tmp)andwrite_atomically(&dir.join(EARLY_FILE), ...), and both operations used fixed.tmpfilenames (host-pipelines.tmp/early-pipelines.tmp).If a second caller entered
save()while the first was still renaminghost-pipelines.tmpor writing/renamingearly-pipelines.tmp, the second caller truncated the same.tmpfile mid-rename (Mapped::create/std::fs::write), causing rename failures or replacinghost-pipelines.bin/early-pipelines.txtwith truncated/corrupt data. Additionally, ifserialise()failed,USED_CHANGEDhad already been cleared tofalse.Fix
SAVE_LOCKmutex inlibrary::save()spanning the full file-write and rename sequence while keepinglibrary.saving.write()scoped toGetSerializedSize()+serialise().temp_path(), keyed by PID and monotonic counter) and remove the temp file if writing or renaming fails.USED_CHANGEDifserialise()fails.temp_paths_are_unique_and_write_atomically_cleans_up.Verification
cargo test -p victory-gpu --locked pipeline::library::tests -- --test-threads=1: 5 passed, 0 failedcargo xtask policy: 169 files okcargo clippy -p victory-gpu --all-targets --locked -- -D warnings: cleancargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: clean(AI-assisted; synthetic unit tests only, no game data.)
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.