remove a level of retries

This commit is contained in:
Bryan Stitt 2023-07-07 14:06:44 -07:00
parent 512bcf305b
commit 57f640765a

@ -53,7 +53,7 @@ use std::sync::{atomic, Arc};
use std::time::Duration;
use tokio::sync::{broadcast, watch, Semaphore, oneshot};
use tokio::task::JoinHandle;
use tokio::time::{sleep, timeout};
use tokio::time::{timeout};
use tracing::{error, info, trace, warn, Level};
// TODO: make this customizable?
@ -1128,45 +1128,31 @@ impl Web3ProxyApp {
let response_id = request.id;
// TODO: trace 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
// TODO: I think we have sufficient retries elsewhere and this will just slow us down.
let mut tries = 3;
let mut last_code_and_response = None;
while tries > 0 {
let (code, response_data) = match self
._proxy_request_with_caching(
&request.method,
&mut request.params,
head_block,
Some(2),
&request_metadata,
)
.await
{
Ok(response_data) => (StatusCode::OK, response_data),
Err(err) => err.as_response_parts(),
};
let (code, response_data) = match self
._proxy_request_with_caching(
&request.method,
&mut request.params,
head_block,
Some(2),
&request_metadata,
)
.await
{
Ok(response_data) => {
request_metadata.error_response.store(false, Ordering::Release);
last_code_and_response = Some((code, response_data));
(StatusCode::OK, response_data)
},
Err(err) => {
request_metadata.error_response.store(true, Ordering::Release);
if code == StatusCode::OK {
break;
}
err.as_response_parts()
},
};
tries -= 1;
// TODO: emit a stat?
// TODO: only log params in development
warn!(method=%request.method, params=%request.params, response=?last_code_and_response, "request failed ({} tries remain)", tries);
// TODO: sleep a randomized amount of time?
sleep(Duration::from_millis(10)).await;
}
let (code, response) = last_code_and_response.expect("there should always be a response");
let response = JsonRpcForwardedResponse::from_response_data(response, response_id);
let response = JsonRpcForwardedResponse::from_response_data(response_data, response_id);
// TODO: this serializes twice :/
request_metadata.add_response(ResponseOrBytes::Response(&response));