From 25f634fe4da68069870f5c6a34462186955aa493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Le=C5=9Bniak?= Date: Tue, 6 Dec 2022 16:33:14 +0100 Subject: [PATCH 1/2] done --- finality-aleph/src/validator_network/outgoing.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/finality-aleph/src/validator_network/outgoing.rs b/finality-aleph/src/validator_network/outgoing.rs index 679b9d0b9b..58d91b7198 100644 --- a/finality-aleph/src/validator_network/outgoing.rs +++ b/finality-aleph/src/validator_network/outgoing.rs @@ -2,7 +2,7 @@ use std::fmt::{Debug, Display, Error as FmtError, Formatter}; use futures::channel::mpsc; use log::{debug, info}; -use tokio::time::{sleep, Duration}; +use tokio::time::{sleep, timeout, Duration}; use crate::validator_network::{ protocols::{ @@ -15,6 +15,7 @@ enum OutgoingError> { Dial(ND::Error), ProtocolNegotiation(PeerAddressInfo, ProtocolNegotiationError), Protocol(PeerAddressInfo, ProtocolError), + TimedOut, } impl> Display for OutgoingError { @@ -32,10 +33,13 @@ impl> Display for OutgoingError "communication with {} failed, protocol error: {}", addr, e ), + TimedOut => write!(f, "dial timeout",), } } } +const DIAL_TIMEOUT: Duration = Duration::from_secs(43); + async fn manage_outgoing>( secret_key: SK, public_key: SK::PublicKey, @@ -45,9 +49,10 @@ async fn manage_outgoing>( data_for_user: mpsc::UnboundedSender, ) -> Result<(), OutgoingError> { debug!(target: "validator-network", "Trying to connect to {}.", public_key); - let stream = dialer - .connect(addresses) + + let stream = timeout(DIAL_TIMEOUT, dialer.connect(addresses)) .await + .map_err(|_| OutgoingError::TimedOut)? .map_err(OutgoingError::Dial)?; let peer_address_info = stream.peer_address_info(); debug!(target: "validator-network", "Performing outgoing protocol negotiation."); From 5e9a3e2935f07d1823c0ac0a4a7a84df3d4478fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Le=C5=9Bniak?= Date: Tue, 6 Dec 2022 17:11:21 +0100 Subject: [PATCH 2/2] no fun with timorl --- finality-aleph/src/validator_network/outgoing.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/finality-aleph/src/validator_network/outgoing.rs b/finality-aleph/src/validator_network/outgoing.rs index 58d91b7198..0b7de4d75b 100644 --- a/finality-aleph/src/validator_network/outgoing.rs +++ b/finality-aleph/src/validator_network/outgoing.rs @@ -38,7 +38,8 @@ impl> Display for OutgoingError } } -const DIAL_TIMEOUT: Duration = Duration::from_secs(43); +/// Arbitrarily chosen timeout, should be more than enough. +const DIAL_TIMEOUT: Duration = Duration::from_secs(60); async fn manage_outgoing>( secret_key: SK,