Skip to content

Commit

Permalink
Do not wait unfinished tokio task if they does not exit after 30 seconds
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <execvy@gmail.com>
  • Loading branch information
eval-exec committed Nov 27, 2023
1 parent 3d674d5 commit 24e4f22
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ckb-bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ mod setup_guard;
mod subcommand;

use ckb_app_config::{cli, ExitCode, Setup};
use ckb_async_runtime::new_global_runtime;
use ckb_async_runtime::{new_global_runtime, tokio::time::timeout};
use ckb_build_info::Version;
use ckb_logger::info;
use ckb_network::tokio;
use helper::raise_fd_limit;
use setup_guard::SetupGuard;

Expand Down Expand Up @@ -79,13 +78,14 @@ pub fn run_app(version: Version) -> Result<(), ExitCode> {
if matches!(cmd, cli::CMD_RUN) {
handle.drop_guard();

tokio::task::block_in_place(|| {
handle.block_on(async move {
info!("waiting all tokio tasks exit...");
handle_stop_rx.blocking_recv();
info!("all tokio tasks and threads have exited, ckb shutdown");
match timeout(std::time::Duration::from_secs(20), handle_stop_rx.recv()).await {
Ok(_) => info!("all tokio tasks and threads have exited, ckb shutdown"),
Err(_) => info!("wait tokio tasks exit time out, ckb shutdown"),
}
});
}

ret
}

Expand Down

0 comments on commit 24e4f22

Please sign in to comment.