From a4c2e38d33fdb6bdcd7d248f5e9c2f2d4449bff2 Mon Sep 17 00:00:00 2001 From: Zekun Li Date: Mon, 24 Jun 2024 12:10:42 -0700 Subject: [PATCH] [health checker] add timeout for disconnecting --- network/framework/src/protocols/health_checker/mod.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/network/framework/src/protocols/health_checker/mod.rs b/network/framework/src/protocols/health_checker/mod.rs index 0e56833953b54..f6894a56453b6 100644 --- a/network/framework/src/protocols/health_checker/mod.rs +++ b/network/framework/src/protocols/health_checker/mod.rs @@ -47,6 +47,7 @@ use futures::{ use rand::{rngs::SmallRng, Rng, SeedableRng}; use serde::{Deserialize, Serialize}; use std::time::Duration; +use tokio::time::timeout; pub mod builder; mod interface; @@ -339,10 +340,11 @@ impl + Unpin> HealthChec ); let peer_network_id = PeerNetworkId::new(self.network_context.network_id(), peer_id); - if let Err(err) = self - .network_interface - .disconnect_peer(peer_network_id) - .await + if let Err(err) = timeout( + Duration::from_millis(50), + self.network_interface.disconnect_peer(peer_network_id), + ) + .await { warn!( NetworkSchema::new(&self.network_context)