The previous keep-alive strategy was to cycle connections in a
round-robin style. However, that will always keep more connections
around than are needed. This new strategy will allow extra connections
to expire when only a few are needed. This is accomplished by prefering
to reuse a connection that was just released to the pool over one that
has been there for a long time.
We've been seeing a strange number of timeouts in our benchmarking.
Handling spurious timeouts as in this patch seems to fix it!
Note that managing the `timeout_start` needs to be done carefully. If
the current time is provided in the wrong place, it's possible requests
would never timeout.
I've had a couple of instances during stress testing now where
Conn::ready would overflow its stack due to recursing on itself. This
moves subsequent calls to ready() into a loop outside the function.
When loading up a client suddenly with thousands of connections, the
default DNS worker count of four cannot keep up and many requests
timeout as a result. Most people don't need a large pool, so making this
configurable is a natural choice.
In the scenario where a request is started on the `Client`, the client
has a full slab, and sockets for a *different* domain are idling in
keep-alive, the new request would previously cause the client to panic!.
This patch adds a `spawn_error` handler which attempts to evict an idle
connection to make space for the new request. If space cannot be made,
the error handler is run (passed `Error::Full`) and the `Handler` is
dropped.
This is a breaking change because of the new variant of `Error`.
Some inefficient use of `Vec` in the client was replaced with `VecDeque`
to support push/pop from either end.
Closes#896Closes#897
BREAKING CHANGE: `RequestUri::AbsolutePath` variant is changed to a struct variant. Consider using `req.path()` or `req.query()` to get the relevant slice.
Methods added to `Client` and `Server` to control read and write
timeouts of the underlying socket.
Keep-Alive is re-enabled by default on the server, with a default
timeout of 5 seconds.
BREAKING CHANGE: This adds 2 required methods to the `NetworkStream`
trait, `set_read_timeout` and `set_write_timeout`. Any local
implementations will need to add them.
Improve the compile-time of downstream crates that use RequestBuilder,
by not forcing them to remonomorphise and recompile its non-generic
methods when they use it: with this change, they can just call the
precompiled versions in the `hyper` object file(s). The `send` method is
the major culprit here, since it is quite large and complicated.
For an extreme example,
extern crate hyper;
fn main() {
hyper::Client::new().get("x").send().unwrap();
}
takes ~4s to compile before this patch (i.e. generic RequestBuilder) and
~2s after. (The time spent interacting with LLVM goes from 2.2s to
0.3s.)
BREAKING CHANGE: `RequestBuilder<U>` should be replaced by `RequestBuilder`.
When an Http11Message knows that the previous response should not
have included a body per RFC7230, and fails to parse the following
response, the bytes are shuffled along, checking for the start of the
next response.
Closes#640
While these methods are marked unstable in libstd, this is behind a
feature flag, `timeouts`. The Client and Server both have
`set_read_timeout` and `set_write_timeout` methods, that will affect all
connections with that entity.
BREAKING CHANGE: Any custom implementation of NetworkStream must now
implement `set_read_timeout` and `set_write_timeout`, so those will
break. Most users who only use the provided streams should work with
no changes needed.
Closes#315
BREAKING CHANGE: Server::https was changed to allow any implementation
of Ssl. Server in general was also changed. HttpConnector no longer
uses SSL; using HttpsConnector instead.
Connector::connect already used &self, and so would require
synchronization to be handled per connector anyway. Adding Sync to the
Client allows users to setup config for a Client once, such as using a
single connection Pool, and then making requests across multiple
threads.
Closes#254
BREAKING CHANGE: Connectors and Protocols passed to the `Client` must
now also have a `Sync` bounds, but this shouldn't break default usage.
BREAKING CHANGE: Any custom Connectors will need to change to &self in
the connect method. Any Connectors that needed the mutablity need to
figure out a synchronization strategy.
Request::with_connector() takes a &NetworkConnector instead of &mut.
Any uses of with_connector will need to change to passing &C.
The client no longer drops the old `Connector` instance, along with its
entire context (such as the settings and pooled connections in the case
of a `Pool` connector); rather, it passes the SSL verifier on to the
`Connector` so that it uses it for any future connections that it needs
to establish.
A regression test is included.
Closes#495
The commit includes an implementation of the new trait method for all
existing trait impls.
BREAKING CHANGE: Adding a new required method to a public trait is a
breaking change.
The errors from openssl were previously boxed into a
Box<std::error::Error>, which lost some specifics and made it difficult
to match against. To solve this, an `Ssl` variant is added to the
`Error` enum of hyper, and is returned when openssl returns specific
errors.
Closes#483
BREAKING CHANGE: Adds a variant to `hyper::Error`, which may break any
exhaustive matches.
The old names followed the old style of including the module name and
"Error" in each variant. The new style is to refer to an error from its
owning module, and variants are now scoped to their enum, so there's no
need to include the enum name in the variant name.
BREAKING CHANGE: The terms `Http` and `Error` have been removed from the Error
type and its variants. `HttpError` should now be accessed as `hyper::Error`,
and variants like `HttpIoError` should be accessed as `Error::Io`.
This adds a connection pool to the Client that is used by default. It
accepts any other NetworkConnector, and simply acts as a
NetworkConnector itself. Other Pools can exist by simply providing a
custom NetworkConnector. This Pool is only used by default if you also
use the default connector, which is `HttpConnector`. If you wish to use
the Pool with a custom connector, you'll need to create the Pool with
your custom connector, and then pass that pool to the
Client::with_connector.
This also adds a method to `NetworkStream`, `close`, which can be used
to know when the Stream should be put down, because a server requested
that the connection close instead of be kept alive.
Closes#363Closes#41
BREAKING CHANGE: This removes the trait `IntoBody`, and instead using
`Into<Body>`, as it's more idiomatic. This will only have broken code
that had custom implementations of `IntoBody`, and can be fixed by
changing them to `Into<Body>`.
Closes#379
BREAKING CHANGE: For people using the default HttpConnector and Client,
everything should continue to just work. If the Client has been
used with a generic parameter, it should be removed.
However, there were some breaking changes to the internals of
NetworkConnectors. Specifically, they no longer return a
NetworkStream, but instead a Into<Box<NetworkStream + Send>>. All
implementations of NetworkStream should continue to just work,
however.
Possible breakages could come from the stricter usage of Send
throughout the Client API.