diff --git a/ckb-bin/src/lib.rs b/ckb-bin/src/lib.rs index 81d9376b070..3723c672f57 100644 --- a/ckb-bin/src/lib.rs +++ b/ckb-bin/src/lib.rs @@ -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; @@ -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 }