From 6d4d8ea840b24795a2a21922bf9d2621b3f81908 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 18 Sep 2023 23:17:55 -0700 Subject: [PATCH] minor refactor of error retry logic --- web3_proxy/src/app/mod.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 76a72e97..c722f7ce 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -1164,10 +1164,16 @@ impl Web3ProxyApp { // TODO: trace/kafka log request.params before we send them to _proxy_request_with_caching which might modify them // turn some of the Web3ProxyErrors into Ok results - // TODO: move this into a helper function let max_tries = 3; let mut tries = 0; loop { + if tries > 0 { + // exponential backoff with jitter + sleep(Duration::from_millis(100)).await; + } + + tries += 1; + let (code, response_data) = match self ._proxy_request_with_caching( &request.method, @@ -1208,15 +1214,13 @@ impl Web3ProxyApp { (StatusCode::OK, response_data) } Err(err) => { - tries += 1; - if tries < max_tries { - // try again after a short delay - // TODO: tune this delay - sleep(Duration::from_millis(100)).await; - + if tries <= max_tries { + // TODO: log the error before retrying continue; } + // max tries exceeded. return the error + request_metadata .error_response .store(true, Ordering::Relaxed);