Skip to content

Commit

Permalink
Don't indefinitely block on shutting down Tokio (paritytech#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 and ltfschoen committed Feb 22, 2023
1 parent 9e96e7a commit 51a16b4
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 51a16b4

Please sign in to comment.