-
Notifications
You must be signed in to change notification settings - Fork 825
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
Default connection and request timeouts of 5 seconds #4928
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,7 +166,7 @@ impl FromStr for ClientConfigKey { | |
} | ||
|
||
/// HTTP client configuration for remote object stores | ||
#[derive(Debug, Clone, Default)] | ||
#[derive(Debug, Clone)] | ||
pub struct ClientOptions { | ||
user_agent: Option<ConfigValue<HeaderValue>>, | ||
content_type_map: HashMap<String, String>, | ||
|
@@ -188,6 +188,35 @@ pub struct ClientOptions { | |
http2_only: ConfigValue<bool>, | ||
} | ||
|
||
impl Default for ClientOptions { | ||
fn default() -> Self { | ||
// Defaults based on | ||
// <https://docs.aws.amazon.com/sdkref/latest/guide/feature-smart-config-defaults.html> | ||
// <https://docs.aws.amazon.com/whitepapers/latest/s3-optimizing-performance-best-practices/timeouts-and-retries-for-latency-sensitive-applications.html> | ||
// Which recommend a connection timeout of 3.1s and a request timeout of 2s | ||
Self { | ||
user_agent: None, | ||
content_type_map: Default::default(), | ||
default_content_type: None, | ||
default_headers: None, | ||
proxy_url: None, | ||
proxy_ca_certificate: None, | ||
proxy_excludes: None, | ||
allow_http: Default::default(), | ||
allow_insecure: Default::default(), | ||
timeout: Some(Duration::from_secs(5).into()), | ||
connect_timeout: Some(Duration::from_secs(5).into()), | ||
pool_idle_timeout: None, | ||
pool_max_idle_per_host: None, | ||
http2_keep_alive_interval: None, | ||
http2_keep_alive_timeout: None, | ||
http2_keep_alive_while_idle: Default::default(), | ||
http1_only: Default::default(), | ||
http2_only: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
impl ClientOptions { | ||
/// Create a new [`ClientOptions`] with default values | ||
pub fn new() -> Self { | ||
|
@@ -367,17 +396,37 @@ impl ClientOptions { | |
/// | ||
/// The timeout is applied from when the request starts connecting until the | ||
/// response body has finished | ||
/// | ||
/// Default is 5 seconds | ||
pub fn with_timeout(mut self, timeout: Duration) -> Self { | ||
self.timeout = Some(ConfigValue::Parsed(timeout)); | ||
self | ||
} | ||
|
||
/// Disables the request timeout | ||
/// | ||
/// See [`Self::with_timeout`] | ||
pub fn with_timeout_disabled(mut self) -> Self { | ||
self.timeout = None; | ||
self | ||
} | ||
|
||
/// Set a timeout for only the connect phase of a Client | ||
/// | ||
/// Default is 5 seconds | ||
pub fn with_connect_timeout(mut self, timeout: Duration) -> Self { | ||
self.connect_timeout = Some(ConfigValue::Parsed(timeout)); | ||
self | ||
} | ||
|
||
/// Disables the connection timeout | ||
/// | ||
/// See [`Self::with_connect_timeout`] | ||
pub fn with_connect_timeout_disabled(mut self) -> Self { | ||
self.timeout = None; | ||
self | ||
} | ||
|
||
/// Set the pool max idle timeout | ||
/// | ||
/// This is the length of time an idle connection will be kept alive | ||
|
@@ -444,7 +493,20 @@ impl ClientOptions { | |
} | ||
} | ||
|
||
pub(crate) fn client(&self) -> super::Result<Client> { | ||
/// Create a [`Client`] with overrides optimised for metadata endpoint access | ||
/// | ||
/// In particular: | ||
/// * Allows HTTP as metadata endpoints do not use TLS | ||
/// * Configures a low connection timeout to provide quick feedback if not present | ||
#[cfg(any(feature = "aws", feature = "gcp", feature = "azure"))] | ||
pub(crate) fn metadata_client(&self) -> Result<Client> { | ||
self.clone() | ||
.with_allow_http(true) | ||
.with_connect_timeout(Duration::from_secs(1)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will help new users who may use the crate without configuring any credentials, which will then default to the metadata credentials, which will then hang indefinitely trying to get credentials from a non-existent metadata endpoint |
||
.client() | ||
} | ||
|
||
pub(crate) fn client(&self) -> Result<Client> { | ||
let mut builder = ClientBuilder::new(); | ||
|
||
match &self.user_agent { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there are
with_{connection_}timeout
methods that acceptsDuration
but notNone
, maybe add two new methodswith_infinite_{connection_}timeout
and with clear doc warnings? Otherwise there is no public way to set these options toNone
. If you NEVER want anyone to set this toNone
, then this shouldn't be anOption
.