Remove legacy panic handling (#37947)
@maxdeviant We can eventually turn down the panic telemetry endpoint, but should probably leave it up while there's still a bunch of stable users hitting it. @maxbrunsfeld We're optimistic that this change also fixed the macos crashed-thread misreporting. We think it was because the `CrashContext::exception` was getting set to `None` only on macos, while on linux it was getting a real exception value from the sigtrap. Now we've unified and it uses `SIGABRT` on both platforms (I need to double check that this works as expected for windows). We unconditionally set `RUST_BACKTRACE=1` for the current process so that we see backtraces when running in a terminal by default. This should be fine but I just wanted to note it since it's a bit abnormal. Release Notes: - N/A --------- Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
co-authored by
Conrad Irwin
parent
116c6549f6
commit
a33af4e9c0
@@ -1,4 +1,4 @@
|
||||
use crash_handler::CrashHandler;
|
||||
use crash_handler::{CrashEventResult, CrashHandler};
|
||||
use log::info;
|
||||
use minidumper::{Client, LoopAction, MinidumpBinary};
|
||||
use release_channel::{RELEASE_CHANNEL, ReleaseChannel};
|
||||
@@ -10,7 +10,7 @@ use std::{
|
||||
env,
|
||||
fs::{self, File},
|
||||
io,
|
||||
panic::Location,
|
||||
panic::{self, PanicHookInfo},
|
||||
path::{Path, PathBuf},
|
||||
process::{self, Command},
|
||||
sync::{
|
||||
@@ -33,7 +33,16 @@ 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() {
|
||||
let old_hook = panic::take_hook();
|
||||
panic::set_hook(Box::new(move |info| {
|
||||
unsafe { env::set_var("RUST_BACKTRACE", "1") };
|
||||
old_hook(info);
|
||||
// prevent the macOS crash dialog from popping up
|
||||
std::process::exit(1);
|
||||
}));
|
||||
return;
|
||||
} else {
|
||||
panic::set_hook(Box::new(panic_hook));
|
||||
}
|
||||
|
||||
let exe = env::current_exe().expect("unable to find ourselves");
|
||||
@@ -71,7 +80,7 @@ pub async fn init(crash_init: InitCrashHandler) {
|
||||
.unwrap();
|
||||
|
||||
let client = Arc::new(client);
|
||||
let handler = crash_handler::CrashHandler::attach(unsafe {
|
||||
let handler = CrashHandler::attach(unsafe {
|
||||
let client = client.clone();
|
||||
crash_handler::make_crash_event(move |crash_context: &crash_handler::CrashContext| {
|
||||
// only request a minidump once
|
||||
@@ -87,7 +96,7 @@ pub async fn init(crash_init: InitCrashHandler) {
|
||||
} else {
|
||||
true
|
||||
};
|
||||
crash_handler::CrashEventResult::Handled(res)
|
||||
CrashEventResult::Handled(res)
|
||||
})
|
||||
})
|
||||
.expect("failed to attach signal handler");
|
||||
@@ -257,8 +266,16 @@ impl minidumper::ServerHandler for CrashServer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_panic(message: String, span: Option<&Location>) {
|
||||
let span = span
|
||||
pub fn panic_hook(info: &PanicHookInfo) {
|
||||
let message = info
|
||||
.payload()
|
||||
.downcast_ref::<&str>()
|
||||
.map(|s| s.to_string())
|
||||
.or_else(|| info.payload().downcast_ref::<String>().cloned())
|
||||
.unwrap_or_else(|| "Box<Any>".to_string());
|
||||
|
||||
let span = info
|
||||
.location()
|
||||
.map(|loc| format!("{}:{}", loc.file(), loc.line()))
|
||||
.unwrap_or_default();
|
||||
|
||||
@@ -281,11 +298,15 @@ pub fn handle_panic(message: String, span: Option<&Location>) {
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
CrashHandler.simulate_signal(crash_handler::Signal::Trap as u32);
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
CrashHandler.simulate_exception(None);
|
||||
break;
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_os = "windows")] {
|
||||
// https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
|
||||
CrashHandler.simulate_exception(Some(234)); // (MORE_DATA_AVAILABLE)
|
||||
break;
|
||||
} else {
|
||||
std::process::abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
thread::sleep(retry_frequency);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user