aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2016-08-08 17:14:01 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2016-08-08 17:53:51 +0000
commit7a622740655bb5fcbd160eb96887032314842e6e (patch)
tree2f30fa07a54e69b084c7e0a8b20f20b34f6bfc3c
parent219ca602ab3f9d7d857bc1640e2b9e01475cdc3d (diff)
downloadgo-7a622740655bb5fcbd160eb96887032314842e6e.tar.gz
go-7a622740655bb5fcbd160eb96887032314842e6e.zip
net/http: make Transport use new connection if over HTTP/2 concurrency limit
The Go HTTP/1 client will make as many new TCP connections as the user requests. The HTTP/2 client tried to have that behavior, but the policy of whether a connection is re-usable didn't take into account the extra 1 stream counting against SETTINGS_MAX_CONCURRENT_STREAMS so in practice users were getting errors. For example, if the server's advertised max concurrent streams is 100 and 200 concurrrent Go HTTP requests ask for a connection at once, all 200 will think they can reuse that TCP connection, but then 100 will fail later when the number of concurrent streams exceeds 100. Instead, recognize the "no cached connections" error value in the shouldRetryRequest method, so those 100 will retry a new connection. This is the conservative fix for Go 1.7 so users don't get errors, and to match the HTTP/1 behavior. Issues #13957 and #13774 are the more involved bugs for Go 1.8. Updates #16582 Updates #13957 Change-Id: I1f15a7ce60c07a4baebca87675836d6fe03993e8 Reviewed-on: https://go-review.googlesource.com/25580 TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Chris Broadfoot <cbro@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
-rw-r--r--src/net/http/transport.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/net/http/transport.go b/src/net/http/transport.go
index 009f3c5b6a..3046de5a8e 100644
--- a/src/net/http/transport.go
+++ b/src/net/http/transport.go
@@ -398,6 +398,15 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) {
// HTTP request on a new connection. The non-nil input error is the
// error from roundTrip.
func (pc *persistConn) shouldRetryRequest(req *Request, err error) bool {
+ if err == http2ErrNoCachedConn {
+ // Issue 16582: if the user started a bunch of
+ // requests at once, they can all pick the same conn
+ // and violate the server's max concurrent streams.
+ // Instead, match the HTTP/1 behavior for now and dial
+ // again to get a new TCP connection, rather than failing
+ // this request.
+ return true
+ }
if err == errMissingHost {
// User error.
return false