minor refactor of error retry logic
This commit is contained in:
parent
5f85a17b19
commit
6d4d8ea840
@ -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
|
// 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
|
// turn some of the Web3ProxyErrors into Ok results
|
||||||
// TODO: move this into a helper function
|
|
||||||
let max_tries = 3;
|
let max_tries = 3;
|
||||||
let mut tries = 0;
|
let mut tries = 0;
|
||||||
loop {
|
loop {
|
||||||
|
if tries > 0 {
|
||||||
|
// exponential backoff with jitter
|
||||||
|
sleep(Duration::from_millis(100)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
tries += 1;
|
||||||
|
|
||||||
let (code, response_data) = match self
|
let (code, response_data) = match self
|
||||||
._proxy_request_with_caching(
|
._proxy_request_with_caching(
|
||||||
&request.method,
|
&request.method,
|
||||||
@ -1208,15 +1214,13 @@ impl Web3ProxyApp {
|
|||||||
(StatusCode::OK, response_data)
|
(StatusCode::OK, response_data)
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
tries += 1;
|
if tries <= max_tries {
|
||||||
if tries < max_tries {
|
// TODO: log the error before retrying
|
||||||
// try again after a short delay
|
|
||||||
// TODO: tune this delay
|
|
||||||
sleep(Duration::from_millis(100)).await;
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// max tries exceeded. return the error
|
||||||
|
|
||||||
request_metadata
|
request_metadata
|
||||||
.error_response
|
.error_response
|
||||||
.store(true, Ordering::Relaxed);
|
.store(true, Ordering::Relaxed);
|
||||||
|
Loading…
Reference in New Issue
Block a user