XGameSave: a blob write fails with ERROR_ACCESS_DENIED when another process briefly holds the file (no retry in replace_file) #2941

Open
opened 2026-11-27 02:50:41 +00:00 by vibryxcx · 1 comment
vibryxcx commented 2026-11-27 02:50:41 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by vibryxcx on 2026-11-27T02:50:41Z.


On Windows, a blob write in an XGameSave update can fail with ERROR_ACCESS_DENIED from MoveFileExW, because another process (most likely Defender) has the file that was just written open for a moment. replace_file in crates/xcl/src/hle/xgameruntime/gamesave.rs tries once, so the whole XGameSaveSubmitUpdate returns E_FAIL. Until #324 / #543 land, the update is also left half applied.

Seen on: amd-dev bf7c82ee, Windows 11 Pro 26200, NTFS, AMD RX 6800 machine (the GPU does not matter here), debug build. The code is the same on main.

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 at gamesave.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 the DirEntry::metadata() size cache.

What fails: with a temporary eprintln! in write_atomic (local only, not committed), the failing call is MoveFileExW(tmp, dest, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) in replace_file:

write_atomic …\Temp\xcl-blob-enum-17724-…\slot\b\blob11 failed: Access is denied. (os error 5)
write_atomic …\Temp\xcl-blob-enum-21192-…\slot\b\blob04 failed: Access is denied. (os error 5)

Why XCL is not the holder: each_blob (the test's reader) takes SAVE_MUTATION, the same lock as apply, 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, retry MoveFileExW a few times with a short sleep (for example up to 5 tries, 10-50 ms apart) when GetLastError() is ERROR_ACCESS_DENIED (5) or ERROR_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::metadata instead of DirEntry::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 MoveFileExW failure 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.

<!-- greyfinch-sync:ivall/xcl:issue:6638941310 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2941). Originally posted by [vibryxcx](https://github.com/vibryxcx) on 2026-11-27T02:50:41Z. --- On Windows, a blob write in an `XGameSave` update can fail with `ERROR_ACCESS_DENIED` from `MoveFileExW`, because another process (most likely Defender) has the file that was just written open for a moment. `replace_file` in `crates/xcl/src/hle/xgameruntime/gamesave.rs` tries once, so the whole `XGameSaveSubmitUpdate` returns `E_FAIL`. Until #324 / #543 land, the update is also left half applied. **Seen on:** `amd-dev` `bf7c82ee`, Windows 11 Pro 26200, NTFS, AMD RX 6800 machine (the GPU does not matter here), debug build. The code is the same on `main`. **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 at `gamesave.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 the `DirEntry::metadata()` size cache. **What fails:** with a temporary `eprintln!` in `write_atomic` (local only, not committed), the failing call is `MoveFileExW(tmp, dest, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)` in `replace_file`: ``` write_atomic …\Temp\xcl-blob-enum-17724-…\slot\b\blob11 failed: Access is denied. (os error 5) write_atomic …\Temp\xcl-blob-enum-21192-…\slot\b\blob04 failed: Access is denied. (os error 5) ``` **Why XCL is not the holder:** `each_blob` (the test's reader) takes `SAVE_MUTATION`, the same lock as `apply`, 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`, retry `MoveFileExW` a few times with a short sleep (for example up to 5 tries, 10-50 ms apart) when `GetLastError()` is `ERROR_ACCESS_DENIED` (5) or `ERROR_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::metadata` instead of `DirEntry::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 `MoveFileExW` failure 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.
ettehn commented 2026-11-27 02:54:06 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by ettehn on 2026-11-27T02:54:06Z.


Reproduced both Windows error codes on main (8b957bec), using its exact replace_file and write_atomic in a standalone Rust fixture on Windows 11 / NTFS. A separate process opened a disposable file without FILE_SHARE_DELETE and released it after 45 ms. Holding the destination caused write_atomic to fail with error 5 in 10/10 runs. Holding the already-written temporary source caused replace_file to 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 MoveFileExW flags 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, and XGameSaveSubmitUpdate entry 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 returned E_FAIL in 10/10 runs after applying the display name and first blob, leaving the later write and deletion untouched. The retry variant returned S_OK in 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.

<!-- greyfinch-sync:ivall/xcl:comment:7208530528 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2941#issuecomment-7208530528). Originally posted by [ettehn](https://github.com/ettehn) on 2026-11-27T02:54:06Z. --- Reproduced both Windows error codes on `main` (`8b957bec`), using its exact `replace_file` and `write_atomic` in a standalone Rust fixture on Windows 11 / NTFS. A separate process opened a disposable file without `FILE_SHARE_DELETE` and released it after 45 ms. Holding the destination caused `write_atomic` to fail with error 5 in 10/10 runs. Holding the already-written temporary source caused `replace_file` to 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 `MoveFileExW` flags 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`, and `XGameSaveSubmitUpdate` entry 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 returned `E_FAIL` in 10/10 runs after applying the display name and first blob, leaving the later write and deletion untouched. The retry variant returned `S_OK` in 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.
Sign in to join this conversation.
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
xcl-dev/xcl#2941
No description provided.