Skip to content

Loader: keep concurrent crash records whole - #3092

Open
neonbyte1 wants to merge 1 commit into
Marvisak:mainfrom
neonbyte1:pr/crash-lock
Open

neonbyte1 wants to merge 1 commit into
Marvisak:mainfrom
neonbyte1:pr/crash-lock

Conversation

@neonbyte1

Copy link
Copy Markdown

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.

…city

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.

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner

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

clquwu added a commit to clquwu/leonida-ultimate that referenced this pull request Nov 26, 2026
…NV checkpoints & gamesave recovery

Wave 29G — P1 world-entry crash forensics, GPU diagnostic breadcrumbs, Win11 scheduling, and save recovery:

- runtime/src/main.cpp:
  - Emit full single-line crash records with access kind, faulting VA, x64 registers (rip/rsp/rax/rcx/rdx/r8/r9), and tid under a 10 ms short-timeout atomic spin guard (adapted from Marvisak/VIctory#3092, GPL-3.0, author neonbyte1) and tee to auto_session_recorder().
  - Add opt-in full-memory minidump writing via dynamic dbghelp.dll MiniDumpWriteDump when LEONIDA_CRASH_DUMP_DIR is set (adapted from Geckomacabre/vx-layer@707b75b, GPL-3.0, author Geckomacabre).
  - Add Windows 11 EcoQoS execution-speed throttling opt-out (PROCESS_POWER_THROTTLING_EXECUTION_SPEED, disable with LEONIDA_EFFICIENCY_MODE=1) and ABOVE_NORMAL process priority class (disable with LEONIDA_PROCESS_PRIORITY=normal|0), alongside 1 ms timer resolution opt-out (adapted from JMAN730/project-flamingo#796, GPL-3.0, author fever308).
- runtime/src/vulkan_device_markers.h + runtime/src/vulkan_device_fault.h:
  - Add standalone GPU breadcrumb marker history & VK_AMD_buffer_marker helper header (adapted from ubiquitarianism/leonida#2187, GPL-3.0, author aslan2142) ready for Wave 30 wiring.
  - Enhance VK_NV_device_diagnostic_checkpoints reporting with human-readable Vulkan pipeline stage names, structured nv_device_fault_checkpoint_lines(), truncation notices, and per-loss summary line.
- runtime/shims/xgameruntime_gamesave.cpp + runtime/test/xgameruntime_gamesave_test.cpp:
  - Fix E_GS_PROVIDED_BUFFER_TOO_SMALL (0x80830007) on compact GDK caller buffers (sizeof(XGameSaveBlob)*N + sum(data + name + 1) without 8-byte padding) while keeping 8-byte alignment when room permits and logging have/need/blobs on genuine buffer-too-small errors.
  - Harden manifest recovery (after Marvisak/VIctory#1981, GPL-3.0, author WerG0D): corrupt .commit restores ~prev backups instead of deleting them; directory-in-place-of-blob rolls back cleanly; present 0-byte blobs roll forward; unrecoverable missing-blob containers preserve .commit and refuse torn reads/updates.
  - Add 5 unit test scenarios covering compact GDK buffer reads and interrupted/corrupt/unrecoverable manifest recovery.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants