Skip to content

Commit 5e83c2b

Browse files
committed
Enable reqwest client-level timeouts
While the `RetryPolicy` has a `MaxTotalDelayRetryPolicy`, the retry `loop` would only check this configured delay once the operation future actually returns a value. However, without client-side timeouts, we're not super sure the operation is actually guaranteed to return anything (even an error, IIUC). So here, we enable some coarse client-side default timeouts to ensure the polled futures eventualy return either the response *or* an error we can handle via our retry logic.
1 parent c5599bc commit 5e83c2b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/client.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::types::{
1414
use crate::util::retry::{retry, RetryPolicy};
1515

1616
const APPLICATION_OCTET_STREAM: &str = "application/octet-stream";
17+
const DEFAULT_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10);
1718

1819
/// Thin-client to access a hosted instance of Versioned Storage Service (VSS).
1920
/// The provided [`VssClient`] API is minimalistic and is congruent to the VSS server-side API.
@@ -31,7 +32,12 @@ where
3132
impl<R: RetryPolicy<E = VssError>> VssClient<R> {
3233
/// Constructs a [`VssClient`] using `base_url` as the VSS server endpoint.
3334
pub fn new(base_url: String, retry_policy: R) -> Self {
34-
let client = Client::new();
35+
let client = Client::builder()
36+
.timeout(DEFAULT_TIMEOUT)
37+
.connect_timeout(DEFAULT_TIMEOUT)
38+
.read_timeout(DEFAULT_TIMEOUT)
39+
.build()
40+
.unwrap();
3541
Self::from_client(base_url, client, retry_policy)
3642
}
3743

@@ -51,7 +57,12 @@ impl<R: RetryPolicy<E = VssError>> VssClient<R> {
5157
pub fn new_with_headers(
5258
base_url: String, retry_policy: R, header_provider: Arc<dyn VssHeaderProvider>,
5359
) -> Self {
54-
let client = Client::new();
60+
let client = Client::builder()
61+
.timeout(DEFAULT_TIMEOUT)
62+
.connect_timeout(DEFAULT_TIMEOUT)
63+
.read_timeout(DEFAULT_TIMEOUT)
64+
.build()
65+
.unwrap();
5566
Self { base_url, client, retry_policy, header_provider }
5667
}
5768

0 commit comments

Comments
 (0)