Skip to content

Commit 0ded36f

Browse files
authored
Rollup merge of #125523 - saethlin:ctrlc-timeout, r=bjorn3
Exit the process a short time after entering our ctrl-c handler Fixes #124212 r? `@bjorn3`
2 parents 64730a1 + f1a18da commit 0ded36f

File tree

1 file changed

+8
-9
lines changed
  • compiler/rustc_driver_impl/src

1 file changed

+8
-9
lines changed

compiler/rustc_driver_impl/src/lib.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use std::process::{self, Command, Stdio};
5757
use std::str;
5858
use std::sync::atomic::{AtomicBool, Ordering};
5959
use std::sync::{Arc, OnceLock};
60-
use std::time::{Instant, SystemTime};
60+
use std::time::{Duration, Instant, SystemTime};
6161
use time::OffsetDateTime;
6262
use tracing::trace;
6363

@@ -1502,14 +1502,13 @@ pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
15021502
pub fn install_ctrlc_handler() {
15031503
#[cfg(not(target_family = "wasm"))]
15041504
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);
15131512
})
15141513
.expect("Unable to install ctrlc handler");
15151514
}

0 commit comments

Comments
 (0)