diff --git a/src/bin/main.rs b/src/bin/main.rs index 192abf9..c024e14 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -26,12 +26,18 @@ fn main() -> Result<(), BoxError> { let rt = tokio::runtime::Builder::new_multi_thread().enable_all().build()?; rt.block_on(async move { let res = main_async(args).await; + // Start a timer to force exit after FORCE_EXIT_TIMEOUT second let _h = tokio::spawn(async move { + log::info!("Starting {}-seconds exit timer", tun2proxy::FORCE_EXIT_TIMEOUT); // Delay some seconds then try to exit current process if not exited yet, normally this case should not happen tokio::time::sleep(std::time::Duration::from_secs(tun2proxy::FORCE_EXIT_TIMEOUT)).await; log::info!("Forcing exit now."); std::process::exit(-1); }); + + log::info!("Runtime.block_on exiting..."); + tokio::time::sleep(std::time::Duration::from_micros(100)).await; + res }) } diff --git a/src/general_api.rs b/src/general_api.rs index bdf0371..64895b3 100644 --- a/src/general_api.rs +++ b/src/general_api.rs @@ -138,6 +138,7 @@ pub fn general_run_for_api(args: Args, tun_mtu: u16, packet_information: bool) - log::info!("Forcing exit now."); std::process::exit(-1); }); + tokio::time::sleep(std::time::Duration::from_micros(100)).await; ret });