Skip to content

D3D12-LOADER-CRASH-NO-STDERR-PANIC: never panic on closed stderr in crash reporting - #2946

Open
bobcatchris wants to merge 1 commit into
ProjectLeonida:mainfrom
bobcatchris:fix/d3d12-loader-crash-no-stderr-panic
Open

bobcatchris wants to merge 1 commit into
ProjectLeonida:mainfrom
bobcatchris:fix/d3d12-loader-crash-no-stderr-panic

Conversation

@bobcatchris

Copy link
Copy Markdown
Contributor

Summary

Claimed in the coordination issue as: D3D12-LOADER-CRASH-NO-STDERR-PANIC (#2570 (comment)).

Prevents d3d12/crates/leonida-loader/src/crash.rs from panicking on a closed/failing stderr pipe during crash reporting:

  • log_crash: writes append_to_log(&text) first and writes to stderr with let _ = write!(std::io::stderr(), "{text}"); instead of eprint!, so a closed stderr pipe never loses the crashes.log entry.
  • report (called from extern "system" VEH/SetUnhandledExceptionFilter): replaces eprintln!("{l}"), eprint!("{said}"), and eprintln!(" saved ...") with fallible let _ = write!/writeln!(std::io::stderr(), ...) and writes append_to_log(&text) before printing said, so a closed stderr pipe never panics/aborts across extern "system" and never skips crashes.log or save_on_crash memory dumps.

Tests & Verification

  • Hardware / OS: Windows 11, Rust 1.98.1, no game files or GPU needed.
  • Red -> Green:
    • Added subprocess test crash::tests::log_crash_and_report_unhandled_write_files_when_stderr_pipe_is_closed verifying both log_crash and report_unhandled (plus two save_on_crash dumps under #[cfg(feature = "diagnostics")]) against a closed stderr pipe.
    • Reverting log_crash to eprint!: FAIL (RED1_EXIT=101).
    • Reverting report to eprintln!: FAIL (RED2_EXIT=101).
    • With the fix:
      • cargo test --locked -p leonida-loader --lib --features diagnostics -- crash::tests: 20 passed, 0 failed.
      • cargo test --locked -p leonida-loader --lib -- crash::tests: 20 passed, 0 failed.
  • python -I tools/d3d12_switches.py --check d3d12/docs/switches.md: exit 0.
  • python -I scripts/check_no_game_data.py d3d12/crates/leonida-loader/src/crash.rs: exit 0.

AI Assistance

AI-assisted using Gemini 4 Neon, including a separate read-only independent review pass (APPROVE; applied optional polish to use 'static byte slices in the save_on_crash test fixture and drop a duplicate import).

@merzleckeier

Copy link
Copy Markdown
Contributor

Independent crash-output check with a closed pipe on 44bf554f merged into 1e3e316c. Under Win64 Wine 11.22 the stock subprocess test passed 3/3 with diagnostics, 3/3 without diagnostics and 3/3 in the diagnostics build combined with #2945 and #2947. It verifies the GPU message, synthetic title line and breakpoint report in the file. The diagnostics build also checks the exact contents of both synthetic dump files.

Restoring only the older per-line eprintln! in report on the combined tree, with the initial file-first log_crash intact, made the same child and outer test exit 101 in all three runs. With the original Cargo binary basename the exact PR passed all 20 crash tests, and the three-PR build passed all 26 crash/profile/stack tests. This uses a direct synthetic exception report under Wine. Native exception dispatch was outside the fixture.

MEASURED with OpenAI Codex and a separate read-only review.

@KelboLive KelboLive 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.

Verified on Windows with Rust 1.100: lib 85/85, all loader targets green, diagnostics crash tests 20/20, clippy -D warnings clean.

The closed-pipe test is real: the child asserts writeln!(stderr, "probe").is_err() before reporting, so every later write has a dead handle, and it checks crashes.log plus both diagnostic dumps. Both guards are load-bearing — reverting report's line write to eprintln!, or moving eprint! back before append_to_log in log_crash, fails the new test with child exit 101.

The approach is right for the context: report is reached from extern "system" filter/handler, where a panic would abort, so removing the panic source with fallible writes (rather than catch_unwind) is the correct fix, and title_output already uses try_lock.

Non-blocking: the panic hook installed by log_crashes_to still calls the previous hook (print(info), crash.rs:54). The default hook ignores stderr errors, but a third-party hook that unwraps could still abort from inside a panic — fine for a follow-up. Also worth remembering the claim is narrower than "never fails": an OOM/allocation abort in the handler is still possible; it is just no longer triggered by stderr.

Merge is clean against current main, #2945/#2947 are disjoint files, and the same-file sibling #2939 also merges cleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants