Эх сурвалжийг харах

feat(fortuna): Add timeout for rpc calls (#2633)

* feat(fortuna): Add timeout for all instrumented rpc calls

* format imports + bump
Amin Moghaddam 6 сар өмнө
parent
commit
6474c70e9c

+ 1 - 1
apps/fortuna/Cargo.lock

@@ -1554,7 +1554,7 @@ dependencies = [
 
 [[package]]
 name = "fortuna"
-version = "7.5.1"
+version = "7.5.2"
 dependencies = [
  "anyhow",
  "axum",

+ 1 - 1
apps/fortuna/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "fortuna"
-version = "7.5.1"
+version = "7.5.2"
 edition = "2021"
 
 [lib]

+ 9 - 2
apps/fortuna/src/eth_utils/traced_client.rs

@@ -11,8 +11,10 @@ use {
         metrics::{counter::Counter, family::Family, histogram::Histogram},
         registry::Registry,
     },
-    std::{str::FromStr, sync::Arc},
+    reqwest::Client,
+    std::{sync::Arc, time::Duration},
     tokio::{sync::RwLock, time::Instant},
+    url::Url,
 };
 
 #[derive(Debug, Clone, PartialEq, Eq, Hash, EncodeLabelSet)]
@@ -114,8 +116,13 @@ impl TracedClient {
         url: &str,
         metrics: Arc<RpcMetrics>,
     ) -> Result<Provider<TracedClient>> {
+        let url: Url = url.try_into()?;
+        let client = Client::builder()
+            .timeout(Duration::from_secs(10))
+            .build()
+            .expect("Failed to create HTTP client");
         Ok(Provider::new(TracedClient {
-            inner: Http::from_str(url)?,
+            inner: Http::new_with_client(url, client),
             chain_id,
             metrics,
         }))