XGameSave: a blob write fails with ERROR_ACCESS_DENIED when another process briefly holds the file (no retry in replace_file) #2941
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 ivall/xcl. Originally posted by vibryxcx on 2026-11-27T02:50:41Z.
On Windows, a blob write in an
XGameSaveupdate can fail withERROR_ACCESS_DENIEDfromMoveFileExW, because another process (most likely Defender) has the file that was just written open for a moment.replace_fileincrates/xcl/src/hle/xgameruntime/gamesave.rstries once, so the wholeXGameSaveSubmitUpdatereturnsE_FAIL. Until #324 / #543 land, the update is also left half applied.Seen on:
amd-devbf7c82ee, Windows 11 Pro 26200, NTFS, AMD RX 6800 machine (the GPU does not matter here), debug build. The code is the same onmain.How it shows up:
hle::xgameruntime::gamesave::tests::blob_enumeration_sees_one_submitted_update, run alone (cargo test -p xcl --lib -- --exact hle::xgameruntime::gamesave::tests::blob_enumeration_sees_one_submitted_update), failed 1 of 3, then 2 of 5. It fails atgamesave.rs:1179, in the writer loop:apply(...) == S_OK, left-2147467259(E_FAIL). That is a different failure from #2421, which fails later at the mixed-enumeration assert because of theDirEntry::metadata()size cache.What fails: with a temporary
eprintln!inwrite_atomic(local only, not committed), the failing call isMoveFileExW(tmp, dest, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)inreplace_file:Why XCL is not the holder:
each_blob(the test's reader) takesSAVE_MUTATION, the same lock asapply, so no XCL code has the blob open during the move. Something outside the process has it open briefly. A real-time antivirus scan of a file that was just written is the usual cause on Windows, and a search indexer can do the same. A user's machine will have one of them, so a title's save can fail the same way. That the failure is intermittent, and comes on different blobs each time, fits this.Suggested fix: in
replace_file, retryMoveFileExWa few times with a short sleep (for example up to 5 tries, 10-50 ms apart) whenGetLastError()isERROR_ACCESS_DENIED(5) orERROR_SHARING_VIOLATION(32), and keep the current error for anything else. A test could hold the destination open with a share mode that blocks the move, release it from another thread after a few ms, and check that the update succeeds. The fix in #2421 (std::fs::metadatainstead ofDirEntry::metadata) does not cover this case.Related: #324 (a failed update is left half applied; it names "a locked file" as one cause, and this is that cause, observed), #543 (fix for #324), #2421 (the same test, a different failure), #722 (another
MoveFileExWfailure in the same function, path length).Not tested: a retail title's save path hitting this (the title here does not reach saving); with Defender turned off (I did not change the machine's security settings);
main.AI use: Claude Code (Claude Opus 5.5) ran the tests, added and removed the local probe, read the code and wrote this issue.
Imported from ivall/xcl. Originally posted by ettehn on 2026-11-27T02:54:06Z.
Reproduced both Windows error codes on
main(8b957bec), using its exactreplace_fileandwrite_atomicin a standalone Rust fixture on Windows 11 / NTFS. A separate process opened a disposable file withoutFILE_SHARE_DELETEand released it after 45 ms. Holding the destination causedwrite_atomicto fail with error 5 in 10/10 runs. Holding the already-written temporary source causedreplace_fileto fail with error 32 in 10/10 runs. This identifies two reproducible sharing cases without attributing the original intermittent failure to a particular process.A local candidate retains both
MoveFileExWflags and retries only errors 5 and 32, with four waits of 10/20/30/40 ms. Both transient cases succeeded 10/10. When the destination stayed held, all 10 trials still returned error 5, preserved the previous bytes, and cleaned up the temporary sibling. A missing-source control still returned error 2. These are single-file tests. Container rollback in #543, long paths in #722 and a retail title were outside this check.Synchronous update follow-up. I also called the extracted
XGameSaveCreateUpdate,XGameSaveSubmitBlobWrite,XGameSaveSubmitBlobDelete, andXGameSaveSubmitUpdateentry points. The synthetic update changes the display name, writes three blobs, and deletes a fourth. A second process briefly held the middle write’s destination. Main returnedE_FAILin 10/10 runs after applying the display name and first blob, leaving the later write and deletion untouched. The retry variant returnedS_OKin 10/10 runs and all changes were present on disk, with no temporary blob left. This uses the synchronous save code in a standalone fixture. Asynchronous dispatch, persistent-failure rollback and a retail title remain outside the test.OpenAI Codex (6.2sol) assisted with verification.