Skip to content

Commit f18c70d

Browse files
authored
Set pool_idle_timeout at 90 seconds for default hyper client (#4284)
## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here --> Fixes: #4282 ## Description <!--- Describe your changes in detail --> Updating our default Hyper client to be configured with a [pool_timer](https://docs.rs/hyper-util/latest/hyper_util/client/legacy/struct.Builder.html#method.pool_timer) and a [pool_idle_timeout](https://docs.rs/hyper-util/latest/hyper_util/client/legacy/struct.Builder.html#method.pool_idle_timeout) value of 90 seconds. Prior to Hyper going 1.0 and the legacy client moving into its own crate a `pool_timer` was not required. Now the pool won't timeout idle connections without one. The default value for the timeout in Hyper 0.14 was [90 seconds](https://docs.rs/hyper/0.14.32/hyper/client/struct.Builder.html#method.pool_idle_timeout), so we are copying that in our current settings. ## Testing <!--- Please describe in detail how you tested your changes --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> This is difficult to test at the moment because Hyper does not support plugging in your own pool implementation, so we cannot instrument the pool itself. There has been some movement towards allowing that, so when that happens we could add tests for this behavior. For the time being we will have to be satisfied that the Hyper client tests this itself. ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [x] For changes to the smithy-rs codegen or runtime crates, I have created a changelog entry Markdown file in the `.changelog` directory, specifying "client," "server," or both in the `applies_to` key. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent 38735d7 commit f18c70d

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

.changelog/hyper-defaults.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
applies_to:
3+
- client
4+
authors:
5+
- landonxjames
6+
references:
7+
- smithy-rs#4282
8+
breaking: false
9+
new_feature: false
10+
bug_fix: true
11+
---
12+
Set the `pool_timer` for the default Hyper client. This is required to allow the `pool_idle_timeout` to work. Now idle connections will be released by the pool after 90 seconds.

aws/rust-runtime/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-runtime/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-runtime/aws-smithy-http-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "aws-smithy-http-client"
33
authors = ["AWS Rust SDK Team <[email protected]>"]
44
description = "HTTP client abstractions for generated smithy clients"
5-
version = "1.1.0"
5+
version = "1.1.1"
66
license = "Apache-2.0"
77
edition = "2021"
88
repository = "https://github.com/smithy-lang/smithy-rs"

rust-runtime/aws-smithy-http-client/src/client.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use hyper_util::client::legacy::connect::{
4444
capture_connection, CaptureConnection, Connect, HttpConnector as HyperHttpConnector, HttpInfo,
4545
};
4646
use hyper_util::client::proxy::matcher::Matcher;
47-
use hyper_util::rt::TokioExecutor;
47+
use hyper_util::rt::{TokioExecutor, TokioTimer};
4848
use std::borrow::Cow;
4949
use std::collections::HashMap;
5050
use std::error::Error;
@@ -193,11 +193,13 @@ impl<Any> ConnectorBuilder<Any> {
193193
C::Future: Unpin + Send + 'static,
194194
C::Error: Into<BoxError>,
195195
{
196-
let client_builder =
197-
self.client_builder
198-
.unwrap_or(hyper_util::client::legacy::Builder::new(
199-
TokioExecutor::new(),
200-
));
196+
let client_builder = self.client_builder.unwrap_or_else(|| {
197+
let mut builder = hyper_util::client::legacy::Builder::new(TokioExecutor::new());
198+
// Explicitly setting the pool_timer is required for connection timeouts to work.
199+
builder.pool_timer(TokioTimer::new());
200+
201+
builder
202+
});
201203
let sleep_impl = self.sleep_impl.or_else(default_async_sleep);
202204
let (connect_timeout, read_timeout) = self
203205
.connector_settings

0 commit comments

Comments
 (0)