From 51d86ade5996c5fbef4ea5da68c74dd6a6694ae0 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 12 Oct 2023 20:48:37 -0700 Subject: [PATCH] handle empty futures --- TODO.md | 2 +- web3_proxy/src/rpcs/one.rs | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index 52521589..c1b06564 100644 --- a/TODO.md +++ b/TODO.md @@ -743,7 +743,7 @@ in another repo: event subscriber - [ ] have an upgrade tier that queries multiple backends at once. returns on first Ok result, collects errors. if no Ok, find the most common error and then respond with that - [ ] give public_recent_ips_salt a better, more general, name - [ ] include tier in the head block logs? -- [ ] i think i use FuturesUnordered when a try_join_all might be better +- [x] i think i use FuturesUnordered when a try_join_all might be better - [ ] since we are read-heavy on our configs, maybe we should use a cache - "using a thread local storage and explicit types" https://docs.rs/arc-swap/latest/arc_swap/cache/struct.Cache.html - [ ] tests for config reloading diff --git a/web3_proxy/src/rpcs/one.rs b/web3_proxy/src/rpcs/one.rs index 280bcb2b..0e5f628f 100644 --- a/web3_proxy/src/rpcs/one.rs +++ b/web3_proxy/src/rpcs/one.rs @@ -853,11 +853,23 @@ impl Web3Rpc { } } - // exit if any of the futures exit - // TODO: have an enum for which one exited? - let (first_exit, _, _) = select_all(futures).await; + if futures.is_empty() { + // we didn't have anything to subscribe to. what should happen? + let clone = self.clone(); - debug!(?first_exit, "subscriptions on {} exited", self); + loop { + sleep(Duration::from_secs(60)).await; + if self.should_disconnect() { + break; + } + } + } else { + // exit if any of the futures exit + // TODO: have an enum for which one exited? + let (first_exit, _, _) = select_all(futures).await; + + debug!(?first_exit, "subscriptions on {} exited", self); + } // clear the head block if let Some(block_and_rpc_sender) = block_and_rpc_sender {