remove a level of retries
This commit is contained in:
parent
512bcf305b
commit
57f640765a
|
@ -53,7 +53,7 @@ use std::sync::{atomic, Arc};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::sync::{broadcast, watch, Semaphore, oneshot};
|
use tokio::sync::{broadcast, watch, Semaphore, oneshot};
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use tokio::time::{sleep, timeout};
|
use tokio::time::{timeout};
|
||||||
use tracing::{error, info, trace, warn, Level};
|
use tracing::{error, info, trace, warn, Level};
|
||||||
|
|
||||||
// TODO: make this customizable?
|
// TODO: make this customizable?
|
||||||
|
@ -1128,45 +1128,31 @@ impl Web3ProxyApp {
|
||||||
|
|
||||||
let response_id = request.id;
|
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 (code, response_data) = match self
|
||||||
let mut tries = 3;
|
._proxy_request_with_caching(
|
||||||
let mut last_code_and_response = None;
|
&request.method,
|
||||||
while tries > 0 {
|
&mut request.params,
|
||||||
let (code, response_data) = match self
|
head_block,
|
||||||
._proxy_request_with_caching(
|
Some(2),
|
||||||
&request.method,
|
&request_metadata,
|
||||||
&mut request.params,
|
)
|
||||||
head_block,
|
.await
|
||||||
Some(2),
|
{
|
||||||
&request_metadata,
|
Ok(response_data) => {
|
||||||
)
|
request_metadata.error_response.store(false, Ordering::Release);
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(response_data) => (StatusCode::OK, response_data),
|
|
||||||
Err(err) => err.as_response_parts(),
|
|
||||||
};
|
|
||||||
|
|
||||||
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 {
|
err.as_response_parts()
|
||||||
break;
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
tries -= 1;
|
let response = JsonRpcForwardedResponse::from_response_data(response_data, response_id);
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
// TODO: this serializes twice :/
|
// TODO: this serializes twice :/
|
||||||
request_metadata.add_response(ResponseOrBytes::Response(&response));
|
request_metadata.add_response(ResponseOrBytes::Response(&response));
|
||||||
|
|
Loading…
Reference in New Issue