Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a HTTP connect timeout - default 10s #1584

Merged
merged 1 commit into from
Jun 3, 2024
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
1 change: 1 addition & 0 deletions crates/service-client/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl HttpClient {
let mut http_connector = HttpConnector::new();
http_connector.enforce_http(false);
http_connector.set_nodelay(true);
http_connector.set_connect_timeout(Some(options.connect_timeout.into()));

HttpClient::new(
builder.build::<_, hyper::Body>(ProxyConnector::new(
Expand Down
26 changes: 25 additions & 1 deletion crates/types/src/config/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use serde_with::serde_as;

/// # HTTP client options
#[serde_as]
#[derive(Debug, Default, Clone, Serialize, Deserialize, derive_builder::Builder)]
#[derive(Debug, Clone, Serialize, Deserialize, derive_builder::Builder)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schemars", schemars(rename = "HttpClientOptions", default))]
#[builder(default)]
Expand All @@ -37,6 +37,30 @@ pub struct HttpOptions {
/// Can be overridden by the `HTTP_PROXY` environment variable.
#[cfg_attr(feature = "schemars", schemars(with = "Option<String>"))]
pub http_proxy: Option<ProxyUri>,
/// # Connect timeout
///
/// How long to wait for a TCP connection to be established before considering
/// it a failed attempt.
#[serde_as(as = "serde_with::DisplayFromStr")]
#[cfg_attr(feature = "schemars", schemars(with = "String"))]
pub connect_timeout: humantime::Duration,
}

impl Default for HttpOptions {
fn default() -> Self {
Self {
http_keep_alive_options: Http2KeepAliveOptions::default(),
http_proxy: None,
connect_timeout: HttpOptions::default_connect_timeout(),
}
}
}

impl HttpOptions {
#[inline]
fn default_connect_timeout() -> humantime::Duration {
(Duration::from_secs(10)).into()
}
}

/// # HTTP/2 Keep alive options
Expand Down
Loading