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

Closed
ashrafsdrop wants to merge 1 commit from upstream-pr/2403 into main
ashrafsdrop commented 2026-11-25 13:02:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ashrafsdrop on 2026-11-25T13:02:54Z.


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).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6605097920 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2403). Originally posted by [ashrafsdrop](https://github.com/ashrafsdrop) on 2026-11-25T13:02:54Z. --- 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).
catminou4 commented 2026-11-25 14:06:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T13:19:20Z.

Review: APPROVED


Tested locally: merged into main 940d32f69b, 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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6058344094 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2403#pullrequestreview-6058344094). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T13:19:20Z. **Review:** APPROVED --- Tested locally: merged into main 940d32f69b, `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.
Marvisak commented 2026-11-25 16:09:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:30:51Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166959708 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2403#issuecomment-7166959708). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:30:51Z. --- <!-- 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)_
cloph-dsp commented 2026-11-25 16:09:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T15:42:18Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167253186 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2403#issuecomment-7167253186). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T15:42:18Z. --- 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.
upstream-sync closed this pull request 2026-11-25 23:04:27 +00:00
Marvisak commented 2026-11-25 23:05:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:09:08Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176001398 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2403#issuecomment-7176001398). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:09:08Z. --- 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

Sign in to join this conversation.
No reviewers
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
Marvisak/VIctory!2401
No description provided.