Skip to content

Commit

Permalink
Add exponential backoff for error loop in torii engine (#1106)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev authored Oct 26, 2023
1 parent a0fa1ad commit 7b5fb2f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/torii/core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down

0 comments on commit 7b5fb2f

Please sign in to comment.