From 7b5fb2f75ea0d04cb33543d67a3a3acaec0dfcbf Mon Sep 17 00:00:00 2001 From: Tarrence van As Date: Thu, 26 Oct 2023 10:48:06 -0400 Subject: [PATCH] Add exponential backoff for error loop in torii engine (#1106) --- crates/torii/core/src/engine.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/torii/core/src/engine.rs b/crates/torii/core/src/engine.rs index 8c7e7312e5..d70c5a79c5 100644 --- a/crates/torii/core/src/engine.rs +++ b/crates/torii/core/src/engine.rs @@ -72,15 +72,25 @@ where warn!("start block ignored, stored head exists and will be used instead"); } + let mut backoff_delay = Duration::from_secs(1); + let max_backoff_delay = Duration::from_secs(60); + loop { if cts.is_cancelled() { break Ok(()); } match self.sync_to_head(head).await { - Ok(latest_block_number) => head = latest_block_number, + Ok(latest_block_number) => { + head = latest_block_number; + backoff_delay = Duration::from_secs(1); + } Err(e) => { error!("getting block: {}", e); + sleep(backoff_delay).await; + if backoff_delay < max_backoff_delay { + backoff_delay *= 2; + } continue; } };