From 288380d4578e6e0be913fea6852226227a6c4170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sat, 9 Mar 2024 01:26:59 +0100 Subject: [PATCH] Lock stderr in panic handler --- compiler/rustc_driver_impl/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index e06d1d245b23f..b748190718772 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -1317,6 +1317,9 @@ pub fn install_ice_hook( panic::update_hook(Box::new( move |default_hook: &(dyn Fn(&PanicInfo<'_>) + Send + Sync + 'static), info: &PanicInfo<'_>| { + // Lock stderr to prevent interleaving of concurrent panics. + let _guard = io::stderr().lock(); + // If the error was caused by a broken pipe then this is not a bug. // Write the error and return immediately. See #98700. #[cfg(windows)]