mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Auto merge of #25662 - jdm:panic-at-the-signal, r=SimonSapin
Try to avoid panicking during I/O in the signal and panic handlers. A bunch of mac WPT processes are sitting in zombie states where a thread has hit a double panic while printing the backtrace. These changes attempt to prevent this issue by ignoring any I/O failures that occur while printing, instead of panicking. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #25513 - [x] These changes do not require tests because they address an intermittent edge case <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
4a6198082c
2 changed files with 16 additions and 9 deletions
|
@ -13,8 +13,8 @@ use std::fmt::{self, Write};
|
|||
use backtrace::{BytesOrWideString, PrintFmt};
|
||||
|
||||
#[inline(never)]
|
||||
pub(crate) fn print() {
|
||||
println!("{:?}", Print {
|
||||
pub(crate) fn print(w: &mut dyn std::io::Write) -> Result<(), std::io::Error> {
|
||||
write!(w, "{:?}", Print {
|
||||
print_fn_address: print as usize,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ use servo::config::opts::{self, ArgumentParsingResult};
|
|||
use servo::config::servo_version;
|
||||
use servo::servo_config::pref;
|
||||
use std::env;
|
||||
use std::io::Write;
|
||||
use std::panic;
|
||||
use std::process;
|
||||
use std::thread;
|
||||
|
@ -57,12 +58,14 @@ fn install_crash_handler() {
|
|||
use std::sync::atomic;
|
||||
static BEEN_HERE_BEFORE: atomic::AtomicBool = atomic::AtomicBool::new(false);
|
||||
if !BEEN_HERE_BEFORE.swap(true, atomic::Ordering::SeqCst) {
|
||||
print!("Stack trace");
|
||||
let stdout = std::io::stdout();
|
||||
let mut stdout = stdout.lock();
|
||||
let _ = write!(&mut stdout, "Stack trace");
|
||||
if let Some(name) = thread::current().name() {
|
||||
print!(" for thread \"{}\"", name);
|
||||
let _ = write!(&mut stdout, " for thread \"{}\"", name);
|
||||
}
|
||||
println!();
|
||||
backtrace::print();
|
||||
let _ = write!(&mut stdout, "\n");
|
||||
let _ = backtrace::print(&mut stdout);
|
||||
}
|
||||
unsafe {
|
||||
_exit(sig);
|
||||
|
@ -131,8 +134,11 @@ pub fn main() {
|
|||
};
|
||||
let current_thread = thread::current();
|
||||
let name = current_thread.name().unwrap_or("<unnamed>");
|
||||
let stdout = std::io::stdout();
|
||||
let mut stdout = stdout.lock();
|
||||
if let Some(location) = info.location() {
|
||||
println!(
|
||||
let _ = writeln!(
|
||||
&mut stdout,
|
||||
"{} (thread {}, at {}:{})",
|
||||
msg,
|
||||
name,
|
||||
|
@ -140,11 +146,12 @@ pub fn main() {
|
|||
location.line()
|
||||
);
|
||||
} else {
|
||||
println!("{} (thread {})", msg, name);
|
||||
let _ = writeln!(&mut stdout, "{} (thread {})", msg, name);
|
||||
}
|
||||
if env::var("RUST_BACKTRACE").is_ok() {
|
||||
backtrace::print();
|
||||
let _ = backtrace::print(&mut stdout);
|
||||
}
|
||||
drop(stdout);
|
||||
|
||||
error!("{}", msg);
|
||||
}));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue