Skip to content

Commit 55a5843

Browse files
committed
feat(aggregator-discovery): add HTTP timeouts
1 parent 2273b77 commit 55a5843

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

internal/mithril-aggregator-discovery/src/http_config_discoverer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use std::{collections::HashMap, time::Duration};
22

33
use anyhow::Context;
44
use reqwest::Client;
@@ -45,6 +45,8 @@ pub struct HttpConfigAggregatorDiscoverer {
4545
}
4646

4747
impl HttpConfigAggregatorDiscoverer {
48+
const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
49+
4850
/// Creates a new `HttpConfigAggregatorDiscoverer` instance with the provided results.
4951
pub fn new(configuration_file_url: &str) -> Self {
5052
Self {
@@ -54,7 +56,7 @@ impl HttpConfigAggregatorDiscoverer {
5456

5557
/// Builds a reqwest HTTP client.
5658
fn build_client(&self) -> StdResult<Client> {
57-
let client_builder = Client::builder();
59+
let client_builder = Client::builder().timeout(Self::HTTP_TIMEOUT);
5860
let client = client_builder.build()?;
5961

6062
Ok(client)

internal/mithril-aggregator-discovery/src/model.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::time::Duration;
2+
13
use mithril_aggregator_client::{AggregatorHttpClient, query::GetAggregatorFeaturesQuery};
24
use mithril_common::{StdResult, messages::AggregatorCapabilities};
35

@@ -30,14 +32,18 @@ pub struct AggregatorEndpoint {
3032
}
3133

3234
impl AggregatorEndpoint {
35+
const HTTP_TIMEOUT: Duration = Duration::from_secs(5);
36+
3337
/// Create a new AggregatorEndpoint instance
3438
pub fn new(url: String) -> Self {
3539
Self { url }
3640
}
3741

3842
/// Retrieve the capabilities of the aggregator
3943
pub async fn retrieve_capabilities(&self) -> StdResult<AggregatorCapabilities> {
40-
let aggregator_client = AggregatorHttpClient::builder(self.url.clone()).build()?;
44+
let aggregator_client = AggregatorHttpClient::builder(self.url.clone())
45+
.with_timeout(Self::HTTP_TIMEOUT)
46+
.build()?;
4147

4248
Ok(aggregator_client
4349
.send(GetAggregatorFeaturesQuery::current())

0 commit comments

Comments
 (0)