From 5dc56cc76f6f0d9e67e7006ba2c17b70b5ad5767 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 3 Mar 2023 22:56:35 +0100 Subject: [PATCH] chore: drop tokio rt on separate thread (#1627) --- bin/reth/src/runner.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/reth/src/runner.rs b/bin/reth/src/runner.rs index 84afc3847f..d0a171f33d 100644 --- a/bin/reth/src/runner.rs +++ b/bin/reth/src/runner.rs @@ -37,12 +37,17 @@ impl CliRunner { // fires the shutdown signal to all tasks spawned via the task executor drop(task_manager); + // drop the tokio runtime on a separate thread because drop blocks until its pools + // (including blocking pool) are shutdown. In other words `drop(tokio_runtime)` would block + // the current thread but we want to exit right away. + std::thread::spawn(move || drop(tokio_runtime)); + // give all tasks that are now being shut down some time to finish before tokio leaks them // see [Runtime::shutdown_timeout](tokio::runtime::Runtime::shutdown_timeout) // TODO: enable this again, when pipeline/stages are not longer blocking tasks - std::process::exit(0); // warn!(target: "reth::cli", "Received shutdown signal, waiting up to 30 seconds for // tasks."); tokio_runtime.shutdown_timeout(Duration::from_secs(30)); + Ok(()) } /// Executes a regular future until completion or until external signal received.