mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: add a 5 second timeout for tokio_runtime shutdown (#8771)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -11,7 +11,7 @@
|
|||||||
//! Entrypoint for running commands.
|
//! Entrypoint for running commands.
|
||||||
|
|
||||||
use reth_tasks::{TaskExecutor, TaskManager};
|
use reth_tasks::{TaskExecutor, TaskManager};
|
||||||
use std::{future::Future, pin::pin};
|
use std::{future::Future, pin::pin, sync::mpsc, time::Duration};
|
||||||
use tracing::{debug, error, trace};
|
use tracing::{debug, error, trace};
|
||||||
|
|
||||||
/// Executes CLI commands.
|
/// Executes CLI commands.
|
||||||
@ -52,17 +52,26 @@ impl CliRunner {
|
|||||||
// after the command has finished or exit signal was received we shutdown the task
|
// after the command has finished or exit signal was received we shutdown the task
|
||||||
// manager which fires the shutdown signal to all tasks spawned via the task
|
// manager which fires the shutdown signal to all tasks spawned via the task
|
||||||
// executor and awaiting on tasks spawned with graceful shutdown
|
// executor and awaiting on tasks spawned with graceful shutdown
|
||||||
task_manager.graceful_shutdown_with_timeout(std::time::Duration::from_secs(10));
|
task_manager.graceful_shutdown_with_timeout(Duration::from_secs(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
// drop the tokio runtime on a separate thread because drop blocks until its pools
|
// `drop(tokio_runtime)` would block the current thread until its pools
|
||||||
// (including blocking pool) are shutdown. In other words `drop(tokio_runtime)` would block
|
// (including blocking pool) are shutdown. Since we want to exit as soon as possible, drop
|
||||||
// the current thread but we want to exit right away.
|
// it on a separate thread and wait for up to 5 seconds for this operation to
|
||||||
|
// complete.
|
||||||
|
let (tx, rx) = mpsc::channel();
|
||||||
std::thread::Builder::new()
|
std::thread::Builder::new()
|
||||||
.name("tokio-runtime-shutdown".to_string())
|
.name("tokio-runtime-shutdown".to_string())
|
||||||
.spawn(move || drop(tokio_runtime))
|
.spawn(move || {
|
||||||
|
drop(tokio_runtime);
|
||||||
|
let _ = tx.send(());
|
||||||
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let _ = rx.recv_timeout(Duration::from_secs(5)).inspect_err(|err| {
|
||||||
|
debug!(target: "reth::cli", %err, "tokio runtime shutdown timed out");
|
||||||
|
});
|
||||||
|
|
||||||
command_res
|
command_res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user