Repository navigation
D3D12-LOADER-CRASH-NO-STDERR-PANIC: never panic on closed stderr in crash reporting - #2946
bobcatchris wants to merge 1 commit into
Conversation
…SH-NO-STDERR-PANIC)
|
Independent crash-output check with a closed pipe on Restoring only the older per-line MEASURED with OpenAI Codex and a separate read-only review. |
KelboLive
left a comment
There was a problem hiding this comment.
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.
Summary
Claimed in the coordination issue as:
D3D12-LOADER-CRASH-NO-STDERR-PANIC(#2570 (comment)).Prevents
d3d12/crates/leonida-loader/src/crash.rsfrom panicking on a closed/failing stderr pipe during crash reporting:log_crash: writesappend_to_log(&text)first and writes to stderr withlet _ = write!(std::io::stderr(), "{text}");instead ofeprint!, so a closed stderr pipe never loses thecrashes.logentry.report(called fromextern "system"VEH/SetUnhandledExceptionFilter): replaceseprintln!("{l}"),eprint!("{said}"), andeprintln!(" saved ...")with falliblelet _ = write!/writeln!(std::io::stderr(), ...)and writesappend_to_log(&text)before printingsaid, so a closed stderr pipe never panics/aborts acrossextern "system"and never skipscrashes.logorsave_on_crashmemory dumps.Tests & Verification
crash::tests::log_crash_and_report_unhandled_write_files_when_stderr_pipe_is_closedverifying bothlog_crashandreport_unhandled(plus twosave_on_crashdumps under#[cfg(feature = "diagnostics")]) against a closed stderr pipe.log_crashtoeprint!: FAIL (RED1_EXIT=101).reporttoeprintln!: FAIL (RED2_EXIT=101).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
'staticbyte slices in thesave_on_crashtest fixture and drop a duplicate import).