Loader: keep concurrent crash records whole #3092

Open
github-bot wants to merge 1 commit from github-bot/gh-3092 into main AGit
Owner

@⁠neonbyte1 on GitHub · 2026-11-26 07:30 UTC · original
neonbyte1:pr/crash-lock → main · +27 −1 · 1 files · 1 commits · open

Split out of #2973, as asked in its review.

WriteFile only promises an atomic append for a single sector, and a crash record spans many. Under Wine, crash::tests::concurrent_crash_records_stay_together saw two records interleave: it writes from several threads of one process, which is the case this fixes.

Each record is now written in one append, under a process-local lock. The handler doesn't wait on it for long, because the exception may come from the thread that holds it. After about 10 ms it writes anyway: a rare interleaving is better than a lost report.

Two processes writing the same log aren't covered; the lock is process-local. I haven't seen that happen, and covering it would need a named mutex taken from inside an exception handler, which I'd rather not add without a case for it.

Tested (Linux, GE-Proton11-14 Wine, RTX 5090): victory-loader tests under cargo xtask wine-test (#1218), 39 passed, 0 failed. Not run on Windows.

AI-assisted (Claude); measured on my machine, no game data shared.

**@⁠neonbyte1** on GitHub · 2026-11-26 07:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/3092) `neonbyte1:pr/crash-lock` → `main` · +27 −1 · 1 files · 1 commits · open Split out of #2973, as asked in its review. `WriteFile` only promises an atomic append for a single sector, and a crash record spans many. Under Wine, `crash::tests::concurrent_crash_records_stay_together` saw two records interleave: it writes from several threads of **one process**, which is the case this fixes. Each record is now written in one append, under a process-local lock. The handler doesn't wait on it for long, because the exception may come from the thread that holds it. After about 10 ms it writes anyway: a rare interleaving is better than a lost report. Two processes writing the same log aren't covered; the lock is process-local. I haven't seen that happen, and covering it would need a named mutex taken from inside an exception handler, which I'd rather not add without a case for it. **Tested** (Linux, GE-Proton11-14 Wine, RTX 5090): `victory-loader` tests under `cargo xtask wine-test` (#1218), 39 passed, 0 failed. Not run on Windows. _AI-assisted (Claude); measured on my machine, no game data shared._
WriteFile only promises atomicity for a single sector, and a crash
record spans many: another reporter can write between its bytes even
with FILE_APPEND_DATA, and under Wine the concurrent-records test saw
it happen. Each record is written in one append under a process-local
lock. A handler never waits on it for long, since an exception may come
from the thread that holds it: one that cannot take it still writes, as
a rare interleaving beats losing the report.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 07:37:10 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 07:49 UTC · original · approved these changes

Tested locally merged onto origin/main (63bcca4) on Windows 11 x64:

  • cargo test -p victory-loader crash::tests -- --test-threads=1: all tests passed (including concurrent_crash_records_stay_together).
  • cargo clippy -p victory-loader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 07:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/3092#pullrequestreview-6070262155) · **approved these changes** Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - `cargo test -p victory-loader crash::tests -- --test-threads=1`: all tests passed (including `concurrent_crash_records_stay_together`). - `cargo clippy -p victory-loader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 08:00 UTC · original · approved these changes

Tested natively on Windows 11 x64 (rustc 1.98.1):

  • cargo clippy -p victory-loader --all-targets --locked -- -D warnings (default and --all-features): clean.
  • cargo test -p victory-loader --locked: 39 passed, 0 failed (35 unit tests + crash_log + load_probe + title_dlls).
  • crash::tests::concurrent_crash_records_stay_together: 10/10 consecutive runs passed.
  • cargo xtask policy: 191 files ok.

The bounded try_lock + yield_now wait (append_guard) with poisoned-lock recovery and timeout fallback is a pragmatic way to serialize multi-thread crash appends without risking self-deadlock if an exception fires while holding the lock.

Two minor non-blocking suggestions:

  • In append_record, acquiring _guard after OpenOptions::new().create(true).append(true).open(file)? (so the mutex only guards the file.write(record.as_bytes()) call rather than handle open/close, which can take milliseconds under Windows AV minifilters) would shrink the critical section and make the 10 ms timeout much less likely to trip under burst contention—FILE_APPEND_DATA already seeks atomically per write across separate handles.
  • Adding a small unit test that holds APPENDING on the current thread and verifies append_record still completes after the ~10 ms timeout would directly cover the re-entrancy fallback path.

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 08:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/3092#pullrequestreview-6070371057) · **approved these changes** Tested natively on Windows 11 x64 (`rustc 1.98.1`): - `cargo clippy -p victory-loader --all-targets --locked -- -D warnings` (default and `--all-features`): clean. - `cargo test -p victory-loader --locked`: 39 passed, 0 failed (35 unit tests + `crash_log` + `load_probe` + `title_dlls`). - `crash::tests::concurrent_crash_records_stay_together`: 10/10 consecutive runs passed. - `cargo xtask policy`: 191 files ok. The bounded `try_lock` + `yield_now` wait (`append_guard`) with poisoned-lock recovery and timeout fallback is a pragmatic way to serialize multi-thread crash appends without risking self-deadlock if an exception fires while holding the lock. Two minor non-blocking suggestions: - In `append_record`, acquiring `_guard` after `OpenOptions::new().create(true).append(true).open(file)?` (so the mutex only guards the `file.write(record.as_bytes())` call rather than handle open/close, which can take milliseconds under Windows AV minifilters) would shrink the critical section and make the 10 ms timeout much less likely to trip under burst contention—`FILE_APPEND_DATA` already seeks atomically per write across separate handles. - Adding a small unit test that holds `APPENDING` on the current thread and verifies `append_record` still completes after the ~10 ms timeout would directly cover the re-entrancy fallback path. LGTM.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 08:19 UTC · original

Automated triage for the maintainers.

Merge candidate. append_record in crates/victory-loader/src/crash.rs now takes a process-local APPENDING lock through append_guard, which only try_locks for up to about 10 ms and then writes anyway, so an exception on the thread holding it cannot deadlock the handler (a poisoned lock is also taken). The record is still formatted before the lock and written in one append, as on main. This answers the earlier review: the interleaving was within one process, and the description states that two processes writing one log are not covered.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 08:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/3092#issuecomment-7186458746) <!-- victory-triage v1 head=f8ea8901197a93010c06cdd13dc3d1c0acd4d78e verdict=merge-candidate at=2026-11-26T08:17:31Z --> Automated triage for the maintainers. **Merge candidate.** `append_record` in `crates/victory-loader/src/crash.rs` now takes a process-local `APPENDING` lock through `append_guard`, which only `try_lock`s for up to about 10 ms and then writes anyway, so an exception on the thread holding it cannot deadlock the handler (a poisoned lock is also taken). The record is still formatted before the lock and written in one append, as on `main`. This answers the earlier review: the interleaving was within one process, and the description states that two processes writing one log are not covered. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Jackster on GitHub · 2026-11-26 16:24 UTC · original

Windows 11 (Win32, not Wine), 63bcca4 + this PR:

  • cargo test -p victory-loader: 35 passed (lib) plus 1 and 2 in the integration suites, 0 failed.
  • cargo clippy -p victory-loader --all-targets -- -D warnings: clean.

One thing worth knowing before merge: crash::tests::concurrent_crash_records_stay_together passes on unpatched 63bcca4 here, 10 runs out of 10, so the interleaving you saw under Wine does not reproduce on Win32 in 10 attempts. The test therefore does not gate the change on Windows, and the Wine evidence stays the reason for it.

Synthetic only. AI-assisted.

**@⁠Jackster** on GitHub · 2026-11-26 16:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3092#issuecomment-7197611685) Windows 11 (Win32, not Wine), `63bcca4` + this PR: - `cargo test -p victory-loader`: 35 passed (lib) plus 1 and 2 in the integration suites, 0 failed. - `cargo clippy -p victory-loader --all-targets -- -D warnings`: clean. One thing worth knowing before merge: `crash::tests::concurrent_crash_records_stay_together` passes on **unpatched** `63bcca4` here, 10 runs out of 10, so the interleaving you saw under Wine does not reproduce on Win32 in 10 attempts. The test therefore does not gate the change on Windows, and the Wine evidence stays the reason for it. Synthetic only. AI-assisted.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 19:51 UTC · original

NVIDIA full-suite run, to go with the reports above by Jackster, fuzeofficlal, since none of them names a GPU run. Tested exact head f8ea890 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 866 passed, 0 failed, 10 ignored.
  • No new #[test] functions in the diff.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-26 19:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/3092#issuecomment-7202033957) NVIDIA full-suite run, to go with the reports above by Jackster, fuzeofficlal, since none of them names a GPU run. Tested exact head `f8ea890` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **866 passed, 0 failed, 10 ignored**. - No new `#[test]` functions in the diff. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3092/head:github-bot/gh-3092'
git switch 'github-bot/gh-3092'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3092'
git switch 'github-bot/gh-3092'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3092'
git switch 'github-bot/gh-3092'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3092'
git switch 'main'
git merge --squash 'github-bot/gh-3092'
git switch 'main'
git merge --ff-only 'github-bot/gh-3092'
git switch 'main'
git merge 'github-bot/gh-3092'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3092
No description provided.