@@ -57,7 +57,7 @@ use std::process::{self, Command, Stdio};
5757use std:: str;
5858use std:: sync:: atomic:: { AtomicBool , Ordering } ;
5959use std:: sync:: { Arc , OnceLock } ;
60- use std:: time:: { Instant , SystemTime } ;
60+ use std:: time:: { Duration , Instant , SystemTime } ;
6161use time:: OffsetDateTime ;
6262use tracing:: trace;
6363
@@ -1502,14 +1502,13 @@ pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
15021502pub 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