XGameRuntime: blob_enumeration_sees_one_submitted_update fails on Windows NTFS (DirEntry::metadata cache) #2411

Open
opened 2026-11-25 18:23:07 +00:00 by Ritolino · 2 comments
Ritolino commented 2026-11-25 18:23:07 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by Ritolino on 2026-11-25T18:23:07Z.


hle::xgameruntime::gamesave::tests::blob_enumeration_sees_one_submitted_update (added in #2165) fails on Windows 11 (NTFS), both under .\scripts\test.ps1 (--test-threads=4) and when run standalone:

thread 'hle::xgameruntime::gamesave::tests::blob_enumeration_sees_one_submitted_update' panicked at crates\xcl\src\hle\xgameruntime\gamesave.rs:1184:9: assertion left == right failed: 2 of 31 enumerations mixed submitted updates

Root cause

Both pply and each_blob hold SAVE_MUTATION, so lobs_of does not run concurrently with MoveFileExW. However, lobs_of (crates\xcl\src\hle\xgameruntime\gamesave.rs:121) reads file sizes via DirEntry::metadata(), which on Windows returns the size cached in the NTFS directory index entry (FindNextFileW), which can lag behind an atomic MoveFileExW replacement across adjacent files.

Using std::fs::metadata(e.path()) (or File::metadata) instead of DirEntry::metadata() should bypass the directory-entry cache, though crates/xcl/src changes require xcl-smoke runs on a real title.

<!-- greyfinch-sync:ivall/xcl:issue:6610951706 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2421). Originally posted by [Ritolino](https://github.com/Ritolino) on 2026-11-25T18:23:07Z. --- hle::xgameruntime::gamesave::tests::blob_enumeration_sees_one_submitted_update (added in #2165) fails on Windows 11 (NTFS), both under .\scripts\test.ps1 (--test-threads=4) and when run standalone: ` thread 'hle::xgameruntime::gamesave::tests::blob_enumeration_sees_one_submitted_update' panicked at crates\xcl\src\hle\xgameruntime\gamesave.rs:1184:9: assertion left == right failed: 2 of 31 enumerations mixed submitted updates ` ### Root cause Both pply and each_blob hold SAVE_MUTATION, so lobs_of does not run concurrently with MoveFileExW. However, lobs_of (crates\xcl\src\hle\xgameruntime\gamesave.rs:121) reads file sizes via DirEntry::metadata(), which on Windows returns the size cached in the NTFS directory index entry (FindNextFileW), which can lag behind an atomic MoveFileExW replacement across adjacent files. Using std::fs::metadata(e.path()) (or File::metadata) instead of DirEntry::metadata() should bypass the directory-entry cache, though crates/xcl/src changes require xcl-smoke runs on a real title.
oni-swr commented 2026-11-25 22:06:37 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-25T21:10:22Z.


Claiming this issue: reproducing and fixing the Windows NTFS DirEntry::metadata() cache race in hle::xgameruntime::gamesave::blobs_of, with regression verification.
AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:ivall/xcl:comment:7174708895 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2421#issuecomment-7174708895). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T21:10:22Z. --- Claiming this issue: reproducing and fixing the Windows NTFS `DirEntry::metadata()` cache race in `hle::xgameruntime::gamesave::blobs_of`, with regression verification. AI use: Claude Code (Claude Opus 5.5).
vibryxcx commented 2026-11-27 02:46:26 +00:00 (Migrated from github.com)
Author
Contributor

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


A second failure mode of the same test, separate from the DirEntry::metadata() cache race above. Noting it here because @oni-swr is on this test, so one fix can cover both.

On an RX 6800 machine (Windows 11 Pro 26200, NTFS, amd-dev bf7c82ee, debug), the test run alone failed 1 of 3, then 2 of 5. It failed earlier than the mixed-enumeration assert, at gamesave.rs:1179, in the writer: apply(...) == S_OK, left -2147467259 (E_FAIL). A temporary eprintln! in write_atomic (local only, removed) showed the failing call: MoveFileExW(tmp, dest, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) in replace_file returned Access is denied. (os error 5), for example on …\slot\b\blob11 and …\slot\b\blob04 under %TEMP%.

each_blob holds SAVE_MUTATION, so the test's reader is not the holder. Something outside XCL had the destination open for a moment, most likely Defender scanning a file that was just written. replace_file makes one attempt, so a single save update fails as a whole, and a title's save could fail the same way on a user's machine. A short bounded retry on ERROR_ACCESS_DENIED / ERROR_SHARING_VIOLATION in replace_file would cover it. The metadata() change alone would not.

Also posted with the suite run in #42. AI use: Claude Code (Claude Opus 5.5) ran the tests, added and removed the probe, and wrote this comment.


Update: this test also leaks its reader thread when it fails, and that is what makes the gamesave module abort with 0xc0000005. On bf7c82ee, module run on its own (cargo test -p xcl --lib -- --test-threads=1 xgameruntime::gamesave::tests): 6 of 20 runs aborted, and in exactly those 6 this test's writer assert (gamesave.rs:1179) fired. Skipping this test gave 0 of 20. The other 10 tests alone, 15 runs each, never abort.

The cause: address = &mut container as *mut Container goes to a detached reader thread. When an assert panics in the main body, the test unwinds and drops container without setting done or joining reader. The reader keeps enumerating the freed stack slot until a later test crashes. So whichever fix lands here (#2521 for the size cache, a retry for #2941), the test should also stop and join the reader on every path, for example with a guard that sets done and joins in Drop, or with std::thread::scope. Otherwise any future failure of this test takes the rest of the module down with it. Details in #42.


Correction (my "cause found" above was wrong about the mechanism). I wrote the fix I suggested: the reader runs in std::thread::scope, with a guard that sets done on drop, so it is always stopped and joined before container goes away. I tested it on main f9a0cb80, gamesave module alone, 20 runs each: the module aborted with 0xc0000005 in 11 of 20 runs without the fix and 11 of 20 with it. In an aborting run with the fix, blob_enumeration_sees_one_submitted_update itself fails cleanly (FAILED), and the next test (case_insensitive_blob_and_container_matching_on_ntfs) then aborts. Skipping blob_enumeration_sees_one_submitted_update still gives 0 of 10 aborts on main. So a failing run of that test is what is followed by the abort, but the detached reader is not the mechanism: something else that the failed test leaves behind takes the next test down. I do not know what yet. My earlier "writer assert fired in exactly those 6" count was also unreliable: when the process aborts, cargo never prints the failure section, so that count could not see failures in aborting runs.

<!-- greyfinch-sync:ivall/xcl:comment:7208419589 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2421#issuecomment-7208419589). Originally posted by [vibryxcx](https://github.com/vibryxcx) on 2026-11-27T02:46:26Z. --- A **second failure mode** of the same test, separate from the `DirEntry::metadata()` cache race above. Noting it here because @oni-swr is on this test, so one fix can cover both. On an RX 6800 machine (Windows 11 Pro 26200, NTFS, `amd-dev` `bf7c82ee`, debug), the test run alone failed 1 of 3, then 2 of 5. It failed earlier than the mixed-enumeration assert, at `gamesave.rs:1179`, in the **writer**: `apply(...) == S_OK`, left `-2147467259` (`E_FAIL`). A temporary `eprintln!` in `write_atomic` (local only, removed) showed the failing call: `MoveFileExW(tmp, dest, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)` in `replace_file` returned **`Access is denied. (os error 5)`**, for example on `…\slot\b\blob11` and `…\slot\b\blob04` under `%TEMP%`. `each_blob` holds `SAVE_MUTATION`, so the test's reader is not the holder. Something outside XCL had the destination open for a moment, most likely Defender scanning a file that was just written. `replace_file` makes one attempt, so a single save update fails as a whole, and a title's save could fail the same way on a user's machine. A short bounded retry on `ERROR_ACCESS_DENIED` / `ERROR_SHARING_VIOLATION` in `replace_file` would cover it. The `metadata()` change alone would not. Also posted with the suite run in #42. AI use: Claude Code (Claude Opus 5.5) ran the tests, added and removed the probe, and wrote this comment. --- **Update: this test also leaks its reader thread when it fails, and that is what makes the `gamesave` module abort with `0xc0000005`.** On `bf7c82ee`, module run on its own (`cargo test -p xcl --lib -- --test-threads=1 xgameruntime::gamesave::tests`): 6 of 20 runs aborted, and in exactly those 6 this test's writer assert (`gamesave.rs:1179`) fired. Skipping this test gave 0 of 20. The other 10 tests alone, 15 runs each, never abort. The cause: `address = &mut container as *mut Container` goes to a detached reader thread. When an assert panics in the main body, the test unwinds and drops `container` without setting `done` or joining `reader`. The reader keeps enumerating the freed stack slot until a later test crashes. So whichever fix lands here (#2521 for the size cache, a retry for #2941), the test should also stop and join the reader on every path, for example with a guard that sets `done` and joins in `Drop`, or with `std::thread::scope`. Otherwise any future failure of this test takes the rest of the module down with it. Details in #42. --- **Correction (my "cause found" above was wrong about the mechanism).** I wrote the fix I suggested: the reader runs in `std::thread::scope`, with a guard that sets `done` on drop, so it is always stopped and joined before `container` goes away. I tested it on `main` `f9a0cb80`, gamesave module alone, 20 runs each: the module aborted with `0xc0000005` in **11 of 20 runs without the fix and 11 of 20 with it**. In an aborting run with the fix, `blob_enumeration_sees_one_submitted_update` itself fails cleanly (`FAILED`), and the **next** test (`case_insensitive_blob_and_container_matching_on_ntfs`) then aborts. Skipping `blob_enumeration_sees_one_submitted_update` still gives 0 of 10 aborts on `main`. So a failing run of that test is what is followed by the abort, but the detached reader is not the mechanism: something else that the failed test leaves behind takes the next test down. I do not know what yet. My earlier "writer assert fired in exactly those 6" count was also unreliable: when the process aborts, cargo never prints the failure section, so that count could not see failures in aborting runs.
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#2411
No description provided.