Handle ConnectionReset+ConnectionAbort at any time (#168)

Previously we had a special case for BadStatusRead that would happen
only when we got a ConnectionAborted error reading the status line.
However, sometimes we get ConnectionReset instead. Also the HTTP
spec says that idempotent requests may be retried anytime a connection
is closed prematurely.

The change treats as retryable any ConnectionAborted OR ConnectionReset
error while reading the status line and headers. It removes the special
case BadStatusRead error.

Fixes #165 (I think).
This commit is contained in:
Jacob Hoffman-Andrews
2020-09-29 01:55:34 -07:00
committed by GitHub
parent 065b560dfb
commit 17d7e147eb
4 changed files with 10 additions and 22 deletions

View File

@@ -189,12 +189,8 @@ pub(crate) fn connect(
// from the ConnectionPool, since those are most likely to have
// reached a server-side timeout. Note that this means we may do
// up to N+1 total tries, where N is max_idle_connections_per_host.
//
// TODO: is_bad_status_read is too narrow since it covers only the
// first line. It's also allowable to retry requests that hit a
// closed connection during the sending or receiving of headers.
if let Some(err) = resp.synthetic_error() {
if err.is_bad_status_read() && retryable && is_recycled {
if err.connection_closed() && retryable && is_recycled {
debug!("retrying request {} {}", method, url);
let empty = Payload::Empty.into_read();
return connect(req, unit, false, redirect_count, empty, redir);