Skip to content

Commit 51a16b4

Browse files
bkchrltfschoen
authored andcommitted
Don't indefinitely block on shutting down Tokio (paritytech#12885)
* Don't indefinitely on shutting down Tokio Now we wait in maximum 60 seconds before we shutdown the node. Tasks are may be leaked and leading to some data corruption. * Drink less :thinking_face:
1 parent 9e96e7a commit 51a16b4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

client/cli/src/runner.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use futures::{future, future::FutureExt, pin_mut, select, Future};
2222
use log::info;
2323
use sc_service::{Configuration, Error as ServiceError, TaskManager};
2424
use sc_utils::metrics::{TOKIO_THREADS_ALIVE, TOKIO_THREADS_TOTAL};
25-
use std::marker::PhantomData;
25+
use std::{marker::PhantomData, time::Duration};
2626

2727
#[cfg(target_family = "unix")]
2828
async fn main<F, E>(func: F) -> std::result::Result<(), E>
@@ -147,7 +147,11 @@ impl<C: SubstrateCli> Runner<C> {
147147
self.print_node_infos();
148148
let mut task_manager = self.tokio_runtime.block_on(initialize(self.config))?;
149149
let res = self.tokio_runtime.block_on(main(task_manager.future().fuse()));
150-
Ok(res?)
150+
151+
// Give all futures 60 seconds to shutdown, before tokio "leaks" them.
152+
self.tokio_runtime.shutdown_timeout(Duration::from_secs(60));
153+
154+
res.map_err(Into::into)
151155
}
152156

153157
/// A helper function that runs a command with the configuration of this node.

0 commit comments

Comments
 (0)