diff options
| author | Mark Fischer <meirfischer@gmail.com> | 2018-04-22 01:16:46 -0400 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2018-07-09 18:32:16 +0000 |
| commit | cae5c7fe88cfdedb517d853730a99e4e319c219f (patch) | |
| tree | ce4445785cc3e0c872e02b378deafec3e8c4b69d /src/net/http/export_test.go | |
| parent | 58d287e5e863cd8d3c3525e1a04e424e748cf242 (diff) | |
| download | go-cae5c7fe88cfdedb517d853730a99e4e319c219f.tar.xz | |
net/http: add Transport.MaxConnsPerHost knob
Add field to http.Transport which limits connections per host,
including dial-in-progress, in-use and idle (keep-alive) connections.
For HTTP/2, this field only controls the number of dials in progress.
Fixes #13957
Change-Id: I7a5e045b4d4793c6b5b1a7191e1342cd7df78e6c
Reviewed-on: https://go-review.googlesource.com/71272
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http/export_test.go')
| -rw-r--r-- | src/net/http/export_test.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/net/http/export_test.go b/src/net/http/export_test.go index 7c7b5d5667..7cdb51b05b 100644 --- a/src/net/http/export_test.go +++ b/src/net/http/export_test.go @@ -133,9 +133,11 @@ func (t *Transport) IdleConnStrsForTesting_h2() []string { return ret } -func (t *Transport) IdleConnCountForTesting(cacheKey string) int { +func (t *Transport) IdleConnCountForTesting(scheme, addr string) int { t.idleMu.Lock() defer t.idleMu.Unlock() + key := connectMethodKey{"", scheme, addr} + cacheKey := key.String() for k, conns := range t.idleConn { if k.String() == cacheKey { return len(conns) @@ -160,13 +162,19 @@ func (t *Transport) RequestIdleConnChForTesting() { t.getIdleConnCh(connectMethod{nil, "http", "example.com"}) } -func (t *Transport) PutIdleTestConn() bool { +func (t *Transport) PutIdleTestConn(scheme, addr string) bool { c, _ := net.Pipe() + key := connectMethodKey{"", scheme, addr} + select { + case <-t.incHostConnCount(key): + default: + return false + } return t.tryPutIdleConn(&persistConn{ t: t, conn: c, // dummy closech: make(chan struct{}), // so it can be closed - cacheKey: connectMethodKey{"", "http", "example.com"}, + cacheKey: key, }) == nil } |
