Browse Source

fix issues of Blocking while exiting

pull/235/head
ssrlive 6 months ago
parent
commit
1212f12b53
  1. 6
      src/bin/main.rs
  2. 1
      src/general_api.rs

6
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
})
}

1
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
});

Loading…
Cancel
Save