Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Avoid suspending panicking thread while crashing (#36645)
Julia Ryanc5ee3f3e2e51
diff --git a/crates/crashes/src/crashes.rs b/crates/crashes/src/crashes.rsindex 4e4b69f639f..b1afc5ae454 100644--- a/crates/crashes/src/crashes.rs+++ b/crates/crashes/src/crashes.rs@@ -4,6 +4,8 @@ use minidumper::{Client, LoopAction, MinidumpBinary};use release_channel::{RELEASE_CHANNEL, ReleaseChannel};use serde::{Deserialize, Serialize};+#[cfg(target_os = "macos")]+use std::sync::atomic::AtomicU32;use std::{env,fs::{self, File},@@ -26,6 +28,9 @@ pub static REQUESTED_MINIDUMP: AtomicBool = AtomicBool::new(false);const CRASH_HANDLER_PING_TIMEOUT: Duration = Duration::from_secs(60);const CRASH_HANDLER_CONNECT_TIMEOUT: Duration = Duration::from_secs(10);+#[cfg(target_os = "macos")]+static PANIC_THREAD_ID: AtomicU32 = AtomicU32::new(0);+pub async fn init(crash_init: InitCrashHandler) {if *RELEASE_CHANNEL == ReleaseChannel::Dev && env::var("ZED_GENERATE_MINIDUMPS").is_err() {return;@@ -110,9 +115,10 @@ unsafe fn suspend_all_other_threads() {mach2::task::task_threads(task, &raw mut threads, &raw mut count);}let current = unsafe { mach2::mach_init::mach_thread_self() };+ let panic_thread = PANIC_THREAD_ID.load(Ordering::SeqCst);for i in 0..count {let t = unsafe { *threads.add(i as usize) };- if t != current {+ if t != current && t != panic_thread {unsafe { mach2::thread_act::thread_suspend(t) };}}@@ -238,6 +244,13 @@ pub fn handle_panic(message: String, span: Option<&Location>) {).ok();log::error!("triggering a crash to generate a minidump...");++ #[cfg(target_os = "macos")]+ PANIC_THREAD_ID.store(+ unsafe { mach2::mach_init::mach_thread_self() },+ Ordering::SeqCst,+ );+#[cfg(target_os = "linux")]CrashHandler.simulate_signal(crash_handler::Signal::Trap as u32);#[cfg(not(target_os = "linux"))]