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

Closed
github-bot wants to merge 1 commit from gh-pr/2403/head into gh-pr/2403/base
Owner

@⁠ashrafsdrop on GitHub · 2026-11-25 13:02 UTC · original
ashrafsdrop:loader/crash-log-serialize-2025 → main · +49 −2 · 1 files · 1 commits · closed without merging

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).
**@⁠ashrafsdrop** on GitHub · 2026-11-25 13:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2403) `ashrafsdrop:loader/crash-log-serialize-2025` → `main` · +49 −2 · 1 files · 1 commits · closed without merging 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 #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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:04:47 +00:00
github-bot closed this pull request 2026-11-26 05:04:47 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:30 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 15:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2403#issuecomment-7166959708) <!-- victory-triage v1 head=ed3d01a69eb250e8f63e6ab7dca4016696dcd272 verdict=merge-candidate at=2026-11-25T15:31:00Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 15:42 UTC · original

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.

**@⁠cloph-dsp** on GitHub · 2026-11-25 15:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2403#issuecomment-7167253186) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:09 UTC · original

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** on GitHub · 2026-11-25 22:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/2403#issuecomment-7176001398) 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.

Pull request closed

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!2403
No description provided.