• Blake Gentry's avatar
    net/http: retry idempotent HTTP reqs on dead reused conns · 5dd372bd
    Blake Gentry authored
    If we try to reuse a connection that the server is in the process of
    closing, we may end up successfully writing out our request (or a
    portion of our request) only to find a connection error when we try to
    read from (or finish writing to) the socket. This manifests as an EOF
    returned from the Transport's RoundTrip.
    
    The issue, among others, is described in #4677.
    
    This change follows some of the Chromium guidelines for retrying
    idempotent requests only when the connection has been already been used
    successfully and no header data has yet been received for the response.
    
    As part of this change, an unexported error was defined for
    errMissingHost, which was previously defined inline. errMissingHost is
    the only non-network error returned from a Request's Write() method.
    
    Additionally, this breaks TestLinuxSendfile because its test server
    explicitly triggers the type of scenario this change is meant to retry
    on. Because that test server stops accepting conns on the test listener
    before the retry, the test would time out. To fix this, the test was
    altered to use a non-idempotent test type (POST).
    
    Change-Id: I1ca630b944f0ed7ec1d3d46056a50fb959481a16
    Reviewed-on: https://go-review.googlesource.com/3210Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
    Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
    5dd372bd
transport_test.go 76.6 KB