Skip to content
Merged
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
30 changes: 18 additions & 12 deletions crates/uv-client/src/base_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use reqwest::{Client, ClientBuilder, IntoUrl, NoProxy, Proxy, Request, Response,
use reqwest_middleware::{ClientWithMiddleware, Middleware};
use reqwest_retry::policies::ExponentialBackoff;
use reqwest_retry::{
RetryPolicy, RetryTransientMiddleware, Retryable, RetryableStrategy, default_on_request_error,
default_on_request_success,
Jitter, RetryPolicy, RetryTransientMiddleware, Retryable, RetryableStrategy,
default_on_request_error, default_on_request_success,
};
use thiserror::Error;
use tracing::{debug, trace};
Expand Down Expand Up @@ -371,11 +371,7 @@ impl<'a> BaseClientBuilder<'a> {

/// Create a [`RetryPolicy`] for the client.
pub fn retry_policy(&self) -> ExponentialBackoff {
let mut builder = ExponentialBackoff::builder();
if env::var_os(EnvVars::UV_TEST_NO_HTTP_RETRY_DELAY).is_some() {
builder = builder.retry_bounds(Duration::from_millis(0), Duration::from_millis(0));
}
builder.build_with_max_retries(self.retries)
retry_policy(self.retries)
}

pub fn build(&self) -> BaseClient {
Expand Down Expand Up @@ -810,11 +806,7 @@ impl BaseClient {

/// The [`RetryPolicy`] for the client.
pub fn retry_policy(&self) -> ExponentialBackoff {
let mut builder = ExponentialBackoff::builder();
if env::var_os(EnvVars::UV_TEST_NO_HTTP_RETRY_DELAY).is_some() {
builder = builder.retry_bounds(Duration::from_millis(0), Duration::from_millis(0));
}
builder.build_with_max_retries(self.retries)
retry_policy(self.retries)
}

pub fn credentials_cache(&self) -> &CredentialsCache {
Expand Down Expand Up @@ -1143,6 +1135,20 @@ impl<'a> RequestBuilder<'a> {
}
}

/// Create a [`RetryPolicy`] with the given number of retries.
fn retry_policy(retries: u32) -> ExponentialBackoff {
let mut builder = ExponentialBackoff::builder();
if env::var_os(EnvVars::UV_TEST_NO_HTTP_RETRY_DELAY).is_some() {
builder = builder.retry_bounds(Duration::from_millis(0), Duration::from_millis(0));
} else {
// Configure an effective minimum between attempts of 1s and a real maximum of 30s.
builder = builder
.jitter(Jitter::Bounded)
.retry_bounds(Duration::from_secs(2), Duration::from_secs(30));
Comment on lines +1145 to +1147
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so for a given $d$ duration and $m$ minimum retry bound, the jitter application gives us $(d - {m\over{2}}) j + {m\over{2}}$ seconds (where $0 &lt; j &lt; 1$), so with $m=2$ and $d_1=2$, $d_2=4$, $d_3=8$ our actual retry delays will be $j+1$, $3j+1$, and $7j+1$, which are between $(1,2)$, $(1,4)$, and $(1,8)$ respectively. Is that what we want?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced by any Jitter option, but those values is better than the ones we currently have.

}
builder.build_with_max_retries(retries)
}

/// An extension over [`DefaultRetryableStrategy`] that logs transient request failures and
/// adds additional retry cases.
pub struct UvRetryableStrategy;
Expand Down