Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ rustls-pemfile = "2"
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = "1.0"
thiserror = "2.0"
tokio = { version = "1.1", features = ["fs", "sync"] }
tokio = { version = "1.1", features = ["fs", "sync", "time"] }
tracing = "0.1.29"
tracing-futures = "0.2.5"
url = "2"
Expand Down
8 changes: 8 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use hyper_util::rt::TokioExecutor;
use ring::rand::SystemRandom;
use ring::signature::{RsaKeyPair, RSA_PKCS1_SHA256};
use serde::{Deserialize, Deserializer};
use tokio::time::sleep;
use tracing::{debug, warn};

use crate::Error;
Expand Down Expand Up @@ -50,7 +51,11 @@ impl HttpClient {
request: &impl Fn() -> Request<Full<Bytes>>,
provider: &'static str,
) -> Result<Arc<Token>, Error> {
//We multiply it by two on every iteration to progressively slow down ourself
//At most we will perform 50 + 100 + 200 + 400 wait as we're limited by 4 re-tries
let mut sleep_interval = Duration::from_millis(50);
let mut retries = 0;

let body = loop {
let err = match self.request(request(), provider).await {
// Early return when the request succeeds
Expand All @@ -67,6 +72,9 @@ impl HttpClient {
if retries >= RETRY_COUNT {
return Err(err);
}

sleep(sleep_interval).await;
sleep_interval *= 2;
};

serde_json::from_slice(&body)
Expand Down
Loading