From c8168adeb2e737bea6830fa0181fa1390be63312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Thu, 14 May 2020 11:49:36 +0100 Subject: [PATCH] Bugfix/issue#231 (#233) * Increasing reconnection attempt after actually computing delay * Constructor mix-up.... * Replaced poll! macro with poll call (after macro expansion that's syntactically identical) --- .../multi-tcp-client/src/connection_manager/mod.rs | 2 +- .../multi-tcp-client/src/connection_manager/reconnector.rs | 2 +- common/client-libs/multi-tcp-client/src/lib.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/client-libs/multi-tcp-client/src/connection_manager/mod.rs b/common/client-libs/multi-tcp-client/src/connection_manager/mod.rs index c1728bad74..0cb5cd3951 100644 --- a/common/client-libs/multi-tcp-client/src/connection_manager/mod.rs +++ b/common/client-libs/multi-tcp-client/src/connection_manager/mod.rs @@ -121,7 +121,7 @@ impl<'a> ConnectionManager<'static> { async fn handle_new_message(&mut self, msg: Vec) -> io::Result<()> { if let ConnectionState::Reconnecting(conn_reconnector) = &mut self.state { // do a single poll rather than await for future to completely resolve - let new_connection = match futures::poll!(conn_reconnector) { + let new_connection = match futures::poll(conn_reconnector).await { Poll::Pending => { return Err(io::Error::new( io::ErrorKind::BrokenPipe, diff --git a/common/client-libs/multi-tcp-client/src/connection_manager/reconnector.rs b/common/client-libs/multi-tcp-client/src/connection_manager/reconnector.rs index f3a14fc6ce..32dd5ad373 100644 --- a/common/client-libs/multi-tcp-client/src/connection_manager/reconnector.rs +++ b/common/client-libs/multi-tcp-client/src/connection_manager/reconnector.rs @@ -71,7 +71,6 @@ impl<'a> Future for ConnectionReconnector<'a> { "we failed to re-establish connection to {} - {:?} (attempt {})", self.address, e, self.current_retry_attempt ); - self.current_retry_attempt += 1; // we failed to re-establish connection - continue exponential backoff @@ -95,6 +94,7 @@ impl<'a> Future for ConnectionReconnector<'a> { self.current_backoff_delay.reset(next); self.connection = tokio::net::TcpStream::connect(self.address).boxed(); + self.current_retry_attempt += 1; Poll::Pending } diff --git a/common/client-libs/multi-tcp-client/src/lib.rs b/common/client-libs/multi-tcp-client/src/lib.rs index 30a4c6da90..4d967f1431 100644 --- a/common/client-libs/multi-tcp-client/src/lib.rs +++ b/common/client-libs/multi-tcp-client/src/lib.rs @@ -60,8 +60,8 @@ impl Client { runtime_handle: Handle::try_current() .expect("The client MUST BE used within tokio runtime context"), connections_managers: HashMap::new(), - initial_reconnection_backoff: config.maximum_reconnection_backoff, - maximum_reconnection_backoff: config.initial_reconnection_backoff, + initial_reconnection_backoff: config.initial_reconnection_backoff, + maximum_reconnection_backoff: config.maximum_reconnection_backoff, initial_connection_timeout: config.initial_connection_timeout, } }