Persist crash records before writing stderr and ignore stderr write failures #4976

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

@⁠mia03ther on GitHub · 2026-12-01 16:10 UTC · original
mia03ther:fix/crash-stderr-panic → main · +80 −16 · 1 files · 1 commits · open

Fixes #4974

What it changes

On Windows, when the process's stderr handle hits quota/pipe failure (os error 1453 — ERROR_NOT_ENOUGH_QUOTA / "配额不足,无法完成请求的服务。" — or os error 109 broken pipe), Rust's standard eprint! / eprintln! and default panic hook panic:

  1. In crates/victory-loader/src/crash.rs, log_crash called eprint!("{text}") before append_to_log(&text). When eprint! panicked inside an FFI / extern "system" frame (or unwound before reaching append_to_log), the host GPU failure message was completely lost from crashes.log and aborted the process with panic in a function that cannot unwind.
  2. In log_crashes_to, the installed panic hook invoked std::panic::take_hook() before append_to_log(...), so if stderr was failing, the default hook panicked recursively before writing the panic record to crashes.log.
  3. In report() (called from extern "system" unhandled-exception and vectored-exception handlers), eprintln! / eprint! ran before append_to_log(&text).

Changes in crates/victory-loader/src/crash.rs:

  • Add non-panicking write_stderr_to / write_stderr helpers (let _ = writer.write_all(text.as_bytes());).
  • Extract log_crash_with so log_crash persists the record to the crash file first, then writes to stderr without panicking on write errors.
  • Update log_crashes_to's panic hook to format and append the panic record via append_to_log first, then best-effort write the standard panic message (and captured backtrace, if any) via write_stderr.
  • Update report() to write header/frame lines to stderr via write_stderr and persist text (append_to_log) before writing title_output() (and any diagnostics save_on_crash lines) via write_stderr.
  • Add unit test crash::tests::log_crash_persists_record_when_stderr_fails_inside_ffi exercising failing stderr (os error 1453 and 109) inside an extern "system" frame.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): not run in-game for this standalone PR branch (victory-loader startup/crash path only; reproduced the live os error 1453 + panic in a function that cannot unwind failure on Windows 11 with v2026.11.30.03).
  • Before: log_crash and report invoked eprint! / eprintln! before writing crashes.log, causing failed printing to stderr: ... (os error 1453) and aborting via panic in a function that cannot unwind with missing crashes.log entries.
  • After: log_crash writes the full record to crashes.log first and ignores stderr write failures cleanly.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): n/a
  • cargo test passed for the crates it touches:
    • cargo clippy -p victory-loader --all-targets --locked -- -D warnings: passed (0 warnings/errors)
    • cargo clippy -p victory-loader --all-targets --all-features --locked -- -D warnings: passed (0 warnings/errors)
    • cargo test -p victory-loader --locked: 77 passed; 0 failed (src\lib.rs), 2 passed; 0 failed (tests\load_probe.rs), 2 passed; 0 failed (tests\title_dlls.rs)
    • cargo test -p victory-loader --lib --all-features --locked -- --test-threads=1: 80 passed; 0 failed (parallel --all-features can hit a pre-existing 0xc0000005 around concurrent cross-thread stack-unwind tests in stacks::tests::another_threads_stack_unwinds_to_its_start)
    • cargo test --locked -p victory-core -p victory-pe: 24 passed; 0 failed (victory-core), 36 passed; 0 failed (victory-pe)
    • cargo xtask policy: passed (asset policy: 464 files ok)
    • Note: workspace-wide cargo clippy --workspace --all-targets --locked -- -D warnings on origin/main (5fabb46) currently fails on 5 pre-existing lint errors in crates/victory-gpu/src/host/{font.rs,menu.rs,panel.rs} tracked by #4708.

Checked for overlap

  • I searched the open pull requests and issues for the same issue and for the files this touches (stderr, 1453, cannot unwind, crash.rs). Related PRs touching crates/victory-loader/src/crash.rs: #4768 (VICTORY_PROFILE periodic/crash flush) and #4132 (stacks: scheduled dumps also go to the crash log). Neither handles stderr write failures (os error 1453) or non-panicking stderr emission in crash/panic handlers.
**@⁠mia03ther** on GitHub · 2026-12-01 16:10 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4975) `mia03ther:fix/crash-stderr-panic` → `main` · +80 −16 · 1 files · 1 commits · open Fixes #4974 ## What it changes On Windows, when the process's stderr handle hits quota/pipe failure (`os error 1453` — `ERROR_NOT_ENOUGH_QUOTA` / `"配额不足,无法完成请求的服务。"` — or `os error 109` broken pipe), Rust's standard `eprint!` / `eprintln!` and default panic hook panic: 1. In `crates/victory-loader/src/crash.rs`, `log_crash` called `eprint!("{text}")` **before** `append_to_log(&text)`. When `eprint!` panicked inside an FFI / `extern "system"` frame (or unwound before reaching `append_to_log`), the host GPU failure message was completely lost from `crashes.log` and aborted the process with `panic in a function that cannot unwind`. 2. In `log_crashes_to`, the installed panic hook invoked `std::panic::take_hook()` **before** `append_to_log(...)`, so if stderr was failing, the default hook panicked recursively before writing the panic record to `crashes.log`. 3. In `report()` (called from `extern "system"` unhandled-exception and vectored-exception handlers), `eprintln!` / `eprint!` ran before `append_to_log(&text)`. Changes in `crates/victory-loader/src/crash.rs`: - Add non-panicking `write_stderr_to` / `write_stderr` helpers (`let _ = writer.write_all(text.as_bytes());`). - Extract `log_crash_with` so `log_crash` persists the record to the crash file **first**, then writes to stderr without panicking on write errors. - Update `log_crashes_to`'s panic hook to format and append the panic record via `append_to_log` first, then best-effort write the standard panic message (and captured backtrace, if any) via `write_stderr`. - Update `report()` to write header/frame lines to stderr via `write_stderr` and persist `text` (`append_to_log`) before writing `title_output()` (and any `diagnostics` `save_on_crash` lines) via `write_stderr`. - Add unit test `crash::tests::log_crash_persists_record_when_stderr_fails_inside_ffi` exercising failing stderr (`os error 1453` and `109`) inside an `extern "system"` frame. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): not run in-game for this standalone PR branch (`victory-loader` startup/crash path only; reproduced the live `os error 1453` + `panic in a function that cannot unwind` failure on Windows 11 with `v2026.11.30.03`). - Before: `log_crash` and `report` invoked `eprint!` / `eprintln!` before writing `crashes.log`, causing `failed printing to stderr: ... (os error 1453)` and aborting via `panic in a function that cannot unwind` with missing `crashes.log` entries. - After: `log_crash` writes the full record to `crashes.log` first and ignores stderr write failures cleanly. - For shader changes, the wave sizes tested (32 and/or 64 lanes): n/a - `cargo test` passed for the crates it touches: - `cargo clippy -p victory-loader --all-targets --locked -- -D warnings`: passed (0 warnings/errors) - `cargo clippy -p victory-loader --all-targets --all-features --locked -- -D warnings`: passed (0 warnings/errors) - `cargo test -p victory-loader --locked`: `77 passed; 0 failed` (`src\lib.rs`), `2 passed; 0 failed` (`tests\load_probe.rs`), `2 passed; 0 failed` (`tests\title_dlls.rs`) - `cargo test -p victory-loader --lib --all-features --locked -- --test-threads=1`: `80 passed; 0 failed` (parallel `--all-features` can hit a pre-existing `0xc0000005` around concurrent cross-thread stack-unwind tests in `stacks::tests::another_threads_stack_unwinds_to_its_start`) - `cargo test --locked -p victory-core -p victory-pe`: `24 passed; 0 failed` (`victory-core`), `36 passed; 0 failed` (`victory-pe`) - `cargo xtask policy`: passed (`asset policy: 464 files ok`) - Note: workspace-wide `cargo clippy --workspace --all-targets --locked -- -D warnings` on `origin/main` (`5fabb46`) currently fails on 5 pre-existing lint errors in `crates/victory-gpu/src/host/{font.rs,menu.rs,panel.rs}` tracked by #4708. ## Checked for overlap - [x] I searched the open pull requests and issues for the same issue and for the files this touches (`stderr`, `1453`, `cannot unwind`, `crash.rs`). Related PRs touching `crates/victory-loader/src/crash.rs`: #4768 (`VICTORY_PROFILE` periodic/crash flush) and #4132 (`stacks: scheduled dumps also go to the crash log`). Neither handles stderr write failures (`os error 1453`) or non-panicking stderr emission in crash/panic handlers.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 16:12:26 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-12-01 16:22 UTC · original · approved these changes

Reviewed crates/victory-loader/src/crash.rs: persisting crash records to crashes.log before writing to stderr and ignoring stderr write errors (write_stderr_to) prevents stderr quota/pipe failures or panics from losing crash diagnostics inside panic hooks and non-unwinding exception handlers. Verified on Windows: cargo test -p victory-loader --lib crash::tests -- --test-threads=1 (22 passed, 0 failed, including log_crash_persists_record_when_stderr_fails_inside_ffi).

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

**@⁠Dukestar69** on GitHub · 2026-12-01 16:22 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4975#pullrequestreview-6135366896) · **approved these changes** Reviewed crates/victory-loader/src/crash.rs: persisting crash records to crashes.log before writing to stderr and ignoring stderr write errors (write_stderr_to) prevents stderr quota/pipe failures or panics from losing crash diagnostics inside panic hooks and non-unwinding exception handlers. Verified on Windows: cargo test -p victory-loader --lib crash::tests -- --test-threads=1 (22 passed, 0 failed, including log_crash_persists_record_when_stderr_fails_inside_ffi). Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/4976/head:github-bot/gh-4975'
git switch 'github-bot/gh-4975'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4975'
git switch 'github-bot/gh-4975'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4975'
git switch 'github-bot/gh-4975'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4975'
git switch 'main'
git merge --squash 'github-bot/gh-4975'
git switch 'main'
git merge --ff-only 'github-bot/gh-4975'
git switch 'main'
git merge 'github-bot/gh-4975'
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/trustno1-coder--VIctory-NVIDIA!4976
No description provided.