fix erroneous retries on a failed request to a newly opened socket #150
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.
In migrating to hyper v1, we encountered an issue with reqwest that we tracked down to hyper-util. I've created a reproduction here.
We see what appears to be aberrant behavior when a client (
reqwest::Client
orhyper_util::client::legacy::Client
) is making a request to a server that may close the connection deliberately. In particular, we see that the client opens a new connection and may try opening connections many many times! If the client is unable to start writing the request to the newly opened connection, it will open a new connection and try again until it's able to write some or all of the request to the socket prior to the server closing it.This appears to be a result of #133 which reintroduced retry logic. It is quite similar to hyperium/hyper@ee61ea9 but diverges in some important ways. In particular:
#133
hyperium/hyper@ee61ea9
Note that the comment has been preserved across the years, but the critical check for
connection_reused
is absent on the new revision.Here are the call-specific error types each commit introduced:
#133
hyperium/hyper@ee61ea9
It seems as though the newer code may have been accidentally similar to the older code rather than intentionally omitting
connection_reused
, but I may be wrong.In this case, we are establishing a new connection. The documentation for
retry_canceled_requests
suggests that the setting should only be applicable for pooled connections that have been reused:This fix borrows from the older code. With it applied, the reproducer above issues a single connection request (which fails, as expected).
I've deleted commented out code that appears to be no longer relevant in that it applies to functionality that is either implemented by #133 (and this fix) or may no longer be applicable. If these deletions were overly cavalier or simply unwanted, I'm happy to revert them.