try timeout inside the cache get again but with shorter timeouts

This commit is contained in:
Bryan Stitt 2023-09-19 18:37:34 -07:00
parent 98da8cdfa7
commit 8a0c2dfdc1
2 changed files with 31 additions and 24 deletions

@ -1734,7 +1734,9 @@ impl Web3ProxyApp {
}; };
// TODO: think more about timeouts // TODO: think more about timeouts
let max_wait = Some(Duration::from_secs(299)); // TODO: different user tiers should have different timeouts
// erigon's timeout is 300, so keep this a few seconds shorter
let max_wait = Some(Duration::from_secs(295));
if let Some(cache_key) = cache_key { if let Some(cache_key) = cache_key {
let from_block_num = cache_key.from_block_num().copied(); let from_block_num = cache_key.from_block_num().copied();
@ -1746,11 +1748,11 @@ impl Web3ProxyApp {
// TODO: try to fetch out of s3 // TODO: try to fetch out of s3
timeout(Duration::from_secs(300), self self
.jsonrpc_response_cache .jsonrpc_response_cache
.try_get_with::<_, Web3ProxyError>(cache_key.hash(), async { .try_get_with::<_, Web3ProxyError>(cache_key.hash(), async {
// TODO: think more about this timeout. we should probably have a `request_expires_at` Duration on the request_metadata // TODO: think more about this timeout. we should probably have a `request_expires_at` Duration on the request_metadata
let response_data = self.balanced_rpcs let response_data = timeout(Duration::from_secs(290), self.balanced_rpcs
.try_proxy_connection::<_, Arc<RawValue>>( .try_proxy_connection::<_, Arc<RawValue>>(
method, method,
params, params,
@ -1758,8 +1760,10 @@ impl Web3ProxyApp {
max_wait, max_wait,
from_block_num.as_ref(), from_block_num.as_ref(),
to_block_num.as_ref(), to_block_num.as_ref(),
).await; )).await;
match response_data {
Ok(response_data) => {
if !cache_jsonrpc_errors && let Err(err) = response_data { if !cache_jsonrpc_errors && let Err(err) = response_data {
// if we are not supposed to cache jsonrpc errors, // if we are not supposed to cache jsonrpc errors,
// then we must not convert Provider errors into a JsonRpcResponseEnum // then we must not convert Provider errors into a JsonRpcResponseEnum
@ -1781,7 +1785,10 @@ impl Web3ProxyApp {
Ok(response_data) Ok(response_data)
} }
} }
})).await?? }
Err(err) => Err(Web3ProxyError::from(err)),
}
}).await?
} else { } else {
let x = timeout( let x = timeout(
Duration::from_secs(300), Duration::from_secs(300),

@ -14,7 +14,7 @@ use std::{
#[derive(Clone, Debug, Eq, From)] #[derive(Clone, Debug, Eq, From)]
pub struct JsonRpcQueryCacheKey { pub struct JsonRpcQueryCacheKey {
/// hashed inputs /// hashed params
hash: u64, hash: u64,
from_block: Option<BlockNumAndHash>, from_block: Option<BlockNumAndHash>,
to_block: Option<BlockNumAndHash>, to_block: Option<BlockNumAndHash>,