move the timeout outside the try_get_with

This commit is contained in:
Bryan Stitt 2023-09-19 09:24:07 -07:00
parent aa8e231a5f
commit 60ffbdfbb2

@ -1743,13 +1743,11 @@ impl Web3ProxyApp {
// TODO: try to fetch out of s3 // TODO: try to fetch out of s3
self timeout(Duration::from_secs(300), 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 proxy_with_timeout= timeout( let response_data = self.balanced_rpcs
Duration::from_secs(300),
self.balanced_rpcs
.try_proxy_connection::<_, Arc<RawValue>>( .try_proxy_connection::<_, Arc<RawValue>>(
method, method,
params, params,
@ -1757,38 +1755,30 @@ 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;
);
match proxy_with_timeout.await { if !cache_jsonrpc_errors && let Err(err) = response_data {
Ok(response_data) => { // if we are not supposed to cache jsonrpc errors,
if !cache_jsonrpc_errors && let Err(err) = response_data { // then we must not convert Provider errors into a JsonRpcResponseEnum
// if we are not supposed to cache jsonrpc errors, // return all the errors now. moka will not cache Err results
// then we must not convert Provider errors into a JsonRpcResponseEnum Err(err)
// return all the errors now. moka will not cache Err results } else {
Err(err) // convert jsonrpc errors into JsonRpcResponseEnum, but leave the rest as errors
} else { let response_data: JsonRpcResponseEnum<Arc<RawValue>> = response_data.try_into()?;
// convert jsonrpc errors into JsonRpcResponseEnum, but leave the rest as errors
let response_data: JsonRpcResponseEnum<Arc<RawValue>> = response_data.try_into()?;
if response_data.is_null() { if response_data.is_null() {
// don't ever cache "null" as a success. its too likely to be a problem // don't ever cache "null" as a success. its too likely to be a problem
Err(Web3ProxyError::NullJsonRpcResult) Err(Web3ProxyError::NullJsonRpcResult)
} else if response_data.num_bytes() > max_response_cache_bytes { } else if response_data.num_bytes() > max_response_cache_bytes {
// don't cache really large requests // don't cache really large requests
// TODO: emit a stat // TODO: emit a stat
Err(Web3ProxyError::JsonRpcResponse(response_data)) Err(Web3ProxyError::JsonRpcResponse(response_data))
} else { } else {
// TODO: response data should maybe be Arc<JsonRpcResponseEnum<Box<RawValue>>>, but that's more work // TODO: response data should maybe be Arc<JsonRpcResponseEnum<Box<RawValue>>>, but that's more work
Ok(response_data) Ok(response_data)
}
}
}
Err(err) => {
Err(Web3ProxyError::from(err))
} }
} }
}).await? })).await??
} else { } else {
let x = timeout( let x = timeout(
Duration::from_secs(300), Duration::from_secs(300),