Skip to content

Commit

Permalink
fix: add timeouts to external api requests
Browse files Browse the repository at this point in the history
  • Loading branch information
xDarksome committed Feb 7, 2024
1 parent 345a4e9 commit 6dbc2c9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = [
build = "build.rs"

[dependencies]
wc = { git = "https://github.com/WalletConnect/utils-rs.git", tag = "v0.7.1", features = ["geoip", "geoblock", "analytics"] }
wc = { git = "https://github.com/WalletConnect/utils-rs.git", tag = "v0.7.1", features = ["geoip", "geoblock", "analytics", "future"] }

tokio = { version = "1", features = ["full"] }

Expand Down
21 changes: 14 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
use {
anyhow::Context as _,
arrayvec::ArrayString,
derive_more::{AsRef, From},
serde::{Deserialize, Serialize},
std::time::Duration,
tap::{Tap, TapFallible, TapOptional},
tracing::{error, instrument, warn},
wc::future::FutureExt as _,
};
pub use {
anyhow::Error,
async_trait::async_trait,
Expand All @@ -6,13 +16,6 @@ pub use {
project_registry::ProjectRegistry,
scam_guard::ScamGuard,
};
use {
arrayvec::ArrayString,
derive_more::{AsRef, From},
serde::{Deserialize, Serialize},
tap::{Tap, TapFallible, TapOptional},
tracing::{error, instrument, warn},
};

pub mod attestation_store;
pub mod cache;
Expand Down Expand Up @@ -100,7 +103,9 @@ impl<'a, I: Infra> Handle<GetVerifyStatus<'a>> for Service<I> {
let project_data = self
.project_registry()
.project_data(cmd.project_id)
.with_timeout(Duration::from_secs(10))
.await
.context("ProjectRegistry::project_data timed out")?
.tap_err(|e| error!("ProjectRegistry::project_data: {e:?}"))?
.ok_or(GetVerifyStatusError::UnknownProject)
.tap_err(|_| warn!("Unknown project id"))?;
Expand Down Expand Up @@ -179,7 +184,9 @@ impl<'a, I: Infra> Handle<GetAttestation<'a>> for Service<I> {
let is_scam = self
.scam_guard()
.is_scam(&origin)
.with_timeout(Duration::from_secs(10))
.await
.context("ScamGuard::is_scam timed out")?
.map_err(|e| error!("ScamGuard::is_scam: {e:?}"))
.unwrap_or(IsScam::Unknown);

Expand Down

0 comments on commit 6dbc2c9

Please sign in to comment.