diff options
| author | Blake Gentry <blakesgentry@gmail.com> | 2015-01-22 15:58:25 -0800 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2015-12-01 20:40:31 +0000 |
| commit | 5dd372bd1e70949a432d9b7b8b021d13abf584d1 (patch) | |
| tree | e2823060e35ef9403a6d511860029794abee2da8 /src/net/http/export_test.go | |
| parent | 7c20ea9311784123b72d9e45c0a29ab5cf838a3c (diff) | |
| download | go-5dd372bd1e70949a432d9b7b8b021d13abf584d1.tar.xz | |
net/http: retry idempotent HTTP reqs on dead reused conns
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/3210
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/http/export_test.go')
| -rw-r--r-- | src/net/http/export_test.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/net/http/export_test.go b/src/net/http/export_test.go index 6e6d1cd725..0dc39a359f 100644 --- a/src/net/http/export_test.go +++ b/src/net/http/export_test.go @@ -125,6 +125,11 @@ func SetPendingDialHooks(before, after func()) { prePendingDial, postPendingDial = before, after } +// SetRetriedHook sets the hook that runs when an idempotent retry occurs. +func SetRetriedHook(hook func()) { + retried = hook +} + var ExportServerNewConn = (*Server).newConn var ExportCloseWriteAndWait = (*conn).closeWriteAndWait |
