Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Don't indefinitely block on shutting down Tokio (#12885)
Browse files Browse the repository at this point in the history
* 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:
  • Loading branch information
bkchr authored Dec 9, 2022
1 parent e6bbc53 commit 90ab4fa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions client/cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use futures::{future, future::FutureExt, pin_mut, select, Future};
use log::info;
use sc_service::{Configuration, Error as ServiceError, TaskManager};
use sc_utils::metrics::{TOKIO_THREADS_ALIVE, TOKIO_THREADS_TOTAL};
use std::marker::PhantomData;
use std::{marker::PhantomData, time::Duration};

#[cfg(target_family = "unix")]
async fn main<F, E>(func: F) -> std::result::Result<(), E>
Expand Down Expand Up @@ -147,7 +147,11 @@ impl<C: SubstrateCli> Runner<C> {
self.print_node_infos();
let mut task_manager = self.tokio_runtime.block_on(initialize(self.config))?;
let res = self.tokio_runtime.block_on(main(task_manager.future().fuse()));
Ok(res?)

// Give all futures 60 seconds to shutdown, before tokio "leaks" them.
self.tokio_runtime.shutdown_timeout(Duration::from_secs(60));

res.map_err(Into::into)
}

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

0 comments on commit 90ab4fa

Please sign in to comment.