Skip to content

Loader: serialize crash-log appends in a single write - #2403

Closed
ashrafsdrop wants to merge 1 commit into
Marvisak:mainfrom
ashrafsdrop:loader/crash-log-serialize-2025
Closed

ashrafsdrop wants to merge 1 commit into
Marvisak:mainfrom
ashrafsdrop:loader/crash-log-serialize-2025

Conversation

@ashrafsdrop

Copy link
Copy Markdown

Addresses the crash-log interleaving reported in #2025:

Summary

  • In crates/victory-loader/src/crash.rs, append_to_log previously used write!(f, ...) without a lock, issuing multiple Write::write calls that interleaved mid-report when concurrent threads hit exceptions or panics.
  • Extracted append_to_file to format the entire entry into a single buffer and write it via write_all under a static LOG_LOCK mutex.

Verification

  • Added concurrent_crash_log_appends_do_not_interleave (8 threads x 25 multi-line appends verified intact).
  • cargo test -p victory-loader (35 unit + 4 integration tests passed).
  • cargo clippy -p victory-loader --all-targets --all-features -- -D warnings (clean).
  • cargo run -p xtask -- policy (182 files ok).

Addresses the crash-log interleaving reported in Marvisak#2025:

- Format each crash/panic log entry into a single buffer and write it via write_all under a static Mutex so concurrent threads never interleave lines mid-report.
- Add concurrent_crash_log_appends_do_not_interleave unit test.

@catminou4 catminou4 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 locally: merged into main 940d32f, cargo test -p victory-loader --locked on macOS arm64. The 3 failures (prepare::tests) are the known pre-existing macOS ones — they parse the host's own Mach-O test binary as PE ("Unknown file magic"), fail identically on main, and are exactly what #2334's #[cfg(windows)] gating removes. Approving — crash-log appends serialized in a single write.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate (worth a look). This fixes interleaved entries in crashes.log (#2025). append_to_log in crates/victory-loader/src/crash.rs used write! on an unbuffered File, which writes in several pieces, so two threads crashing or panicking together could mix their reports. Each entry is now formatted into one buffer and written with a single write_all under a static LOG_LOCK. I checked that all three callers (the panic hook, log_crash, the exception handler) still go through it, that tempfile is already a loader dev-dependency, and that as_chunks is already used in the workspace. Residual risk: the exception handler now takes a lock, so a fault on a thread already inside this write would wait on itself; that case is very narrow. CI: passing.


Generated by Claude Code

@cloph-dsp

Copy link
Copy Markdown

Independent local validation, PR #2403 (Windows, Rust 1.100.0/MSVC, head ed3d01a, no game data): cargo test --locked -p victory-loader --lib -> 35 tests passed, 0 failed, 0 ignored, exit 0; git diff --check clean. CPU-only regression run; the single-write crash-log append scenario was not replayed. AI-assisted (Hy4 flash). GPU/driver: N/A (CPU tests). No game data or third-party assets used.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing in favour of #2033, which makes the same single buffered write without the mutex. One WriteFile on an append handle already lands whole across threads and processes. The lock adds nothing on top and sits in the exception path, where a thread that faults or is ended while holding it would block every later crash report.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026
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