Exit the process a short time after entering our ctrl-c handler

This commit is contained in:
Ben Kimock 2024-05-24 17:43:02 -04:00
parent 213ad10c8f
commit f1a18da4bb

View File

@ -57,7 +57,7 @@
use std::str; use std::str;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, OnceLock}; use std::sync::{Arc, OnceLock};
use std::time::{Instant, SystemTime}; use std::time::{Duration, Instant, SystemTime};
use time::OffsetDateTime; use time::OffsetDateTime;
use tracing::trace; use tracing::trace;
@ -1502,14 +1502,13 @@ pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
pub fn install_ctrlc_handler() { pub fn install_ctrlc_handler() {
#[cfg(not(target_family = "wasm"))] #[cfg(not(target_family = "wasm"))]
ctrlc::set_handler(move || { ctrlc::set_handler(move || {
// Indicate that we have been signaled to stop. If we were already signaled, exit // Indicate that we have been signaled to stop, then give the rest of the compiler a bit of
// immediately. In our interpreter loop we try to consult this value often, but if for // time to check CTRL_C_RECEIVED and run its own shutdown logic, but after a short amount
// whatever reason we don't get to that check or the cleanup we do upon finding that // of time exit the process. This sleep+exit ensures that even if nobody is checking
// this bool has become true takes a long time, the exit here will promptly exit the // CTRL_C_RECEIVED, the compiler exits reasonably promptly.
// process on the second Ctrl-C. CTRL_C_RECEIVED.store(true, Ordering::Relaxed);
if CTRL_C_RECEIVED.swap(true, Ordering::Relaxed) { std::thread::sleep(Duration::from_millis(100));
std::process::exit(1); std::process::exit(1);
}
}) })
.expect("Unable to install ctrlc handler"); .expect("Unable to install ctrlc handler");
} }