From ed505cdd23e79f8e58c3d68e07e2c45c8fe83dc4 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Wed, 14 Sep 2022 06:38:53 +0000 Subject: [PATCH] fix check for http providers even the websocket providers have an http_client set. maybe drop that? --- web3_proxy/src/rpcs/connection.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/web3_proxy/src/rpcs/connection.rs b/web3_proxy/src/rpcs/connection.rs index cdb16ed3..c82d6f1d 100644 --- a/web3_proxy/src/rpcs/connection.rs +++ b/web3_proxy/src/rpcs/connection.rs @@ -269,7 +269,11 @@ impl Web3Connection { cap_ms, rand::thread_rng().gen_range(base_ms..(base_ms * range_multiplier)), ); - sleep(Duration::from_millis(first_sleep_ms)).await; + let reconnect_in = Duration::from_millis(first_sleep_ms); + + warn!(rpc=%self, ?reconnect_in, "Reconnect in"); + + sleep(reconnect_in).await; first_sleep_ms } else { @@ -301,19 +305,22 @@ impl Web3Connection { ) -> anyhow::Result<()> { // since this lock is held open over an await, we use tokio's locking // TODO: timeout on this lock. if its slow, something is wrong - let mut provider = self.provider.write().await; + let mut provider_option = self.provider.write().await; - if provider.is_some() { - if self.http_client.is_some() { - // http clients don't need to do anything for reconnecting - // they *do* need to run this function to setup the first - return Ok(()); + if let Some(provider) = &*provider_option { + match provider.as_ref() { + Web3Provider::Http(_) => { + // http clients don't need to do anything for reconnecting + // they *do* need to run this function to setup the first + return Ok(()); + } + Web3Provider::Ws(_) => {} } info!(rpc=%self, "reconnecting"); // disconnect the current provider - *provider = None; + *provider_option = None; // reset sync status { @@ -335,7 +342,7 @@ impl Web3Connection { // TODO: if this fails, keep retrying! otherwise it crashes and doesn't try again! let new_provider = Web3Provider::from_str(&self.url, self.http_client.clone()).await?; - *provider = Some(Arc::new(new_provider)); + *provider_option = Some(Arc::new(new_provider)); info!(rpc=%self, "successfully connected");