Repository: seanmonstar/reqwest (language: rust)

Issue:
Idle connections are kept in the connection pool forever in some cases
As explained in https://github.com/hyperium/hyper/issues/2420, reqwest seems to keep idle connections around forever in certain cases. For example, when we make a request to some domain once and then never make a request to it again, that connection will stay in the pool forever or at least for a very long time.

This causes problems if the `Client` is used in a long-running application because the process may end up hitting the file descriptor limit on Linux.

`hyper` implements an interval cleanup task but it's gated behind a feature - `runtime` - which is not enabled in `reqwest`:
https://github.com/hyperium/hyper/blob/4d2125c67c8087de863f74278a017c4caf37e6a9/src/client/pool.rs#L402

Enabling `hyper`'s `runtime` feature in `reqwest` does resolve the issue but it might have other consequences...


Discussion / hints:
I don't think there's any downsides for reqwest to enable that feature now. It used to be a heavier feature, but now it's mostly just timeout support.

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index 56fb96995..cce2a28ae 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -91,7 +91,7 @@ encoding_rs = "0.8"
 futures-core = { version = "0.3.0", default-features = false }
 futures-util = { version = "0.3.0", default-features = false }
 http-body = "0.4.0"
-hyper = { version = "0.14", default-features = false, features = ["tcp", "http1", "http2", "client"] }
+hyper = { version = "0.14", default-features = false, features = ["tcp", "http1", "http2", "client", "runtime"] }
 lazy_static = "1.4"
 log = "0.4"
 mime = "0.3.7"
@@ -131,7 +131,7 @@ trust-dns-resolver = { version = "0.20", optional = true }
 
 [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
 env_logger = "0.8"
-hyper = { version = "0.14", default-features = false, features = ["tcp", "stream", "http1", "http2", "client", "server"] }
+hyper = { version = "0.14", default-features = false, features = ["tcp", "stream", "http1", "http2", "client", "server", "runtime"] }
 serde = { version = "1.0", features = ["derive"] }
 libflate = "1.0"
 brotli_crate = { package = "brotli", version = "3.3.0" }


Test patch: