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