mirror of
https://github.com/golang/go.git
synced 2025-05-30 19:52:53 +00:00
net/http: defer idleMu.Unlock() in tryPutIdleConn + minor typo fixes.
Change-Id: Ia2273c3a9f0001d16b0c767fea91498a9acb0af5 Reviewed-on: https://go-review.googlesource.com/19963 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
c7917de0bb
commit
637e1aad5c
@ -118,7 +118,7 @@ type Transport struct {
|
|||||||
DisableCompression bool
|
DisableCompression bool
|
||||||
|
|
||||||
// MaxIdleConnsPerHost, if non-zero, controls the maximum idle
|
// MaxIdleConnsPerHost, if non-zero, controls the maximum idle
|
||||||
// (keep-alive) to keep per-host. If zero,
|
// (keep-alive) connections to keep per-host. If zero,
|
||||||
// DefaultMaxIdleConnsPerHost is used.
|
// DefaultMaxIdleConnsPerHost is used.
|
||||||
MaxIdleConnsPerHost int
|
MaxIdleConnsPerHost int
|
||||||
|
|
||||||
@ -533,7 +533,9 @@ func (t *Transport) tryPutIdleConn(pconn *persistConn) error {
|
|||||||
max = DefaultMaxIdleConnsPerHost
|
max = DefaultMaxIdleConnsPerHost
|
||||||
}
|
}
|
||||||
pconn.markReused()
|
pconn.markReused()
|
||||||
|
|
||||||
t.idleMu.Lock()
|
t.idleMu.Lock()
|
||||||
|
defer t.idleMu.Unlock()
|
||||||
|
|
||||||
waitingDialer := t.idleConnCh[key]
|
waitingDialer := t.idleConnCh[key]
|
||||||
select {
|
select {
|
||||||
@ -543,7 +545,6 @@ func (t *Transport) tryPutIdleConn(pconn *persistConn) error {
|
|||||||
// actively dialing, but this conn is ready
|
// actively dialing, but this conn is ready
|
||||||
// first). Chrome calls this socket late binding. See
|
// first). Chrome calls this socket late binding. See
|
||||||
// https://insouciant.org/tech/connection-management-in-chromium/
|
// https://insouciant.org/tech/connection-management-in-chromium/
|
||||||
t.idleMu.Unlock()
|
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
if waitingDialer != nil {
|
if waitingDialer != nil {
|
||||||
@ -553,14 +554,12 @@ func (t *Transport) tryPutIdleConn(pconn *persistConn) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if t.wantIdle {
|
if t.wantIdle {
|
||||||
t.idleMu.Unlock()
|
|
||||||
return errWantIdle
|
return errWantIdle
|
||||||
}
|
}
|
||||||
if t.idleConn == nil {
|
if t.idleConn == nil {
|
||||||
t.idleConn = make(map[connectMethodKey][]*persistConn)
|
t.idleConn = make(map[connectMethodKey][]*persistConn)
|
||||||
}
|
}
|
||||||
if len(t.idleConn[key]) >= max {
|
if len(t.idleConn[key]) >= max {
|
||||||
t.idleMu.Unlock()
|
|
||||||
return errTooManyIdle
|
return errTooManyIdle
|
||||||
}
|
}
|
||||||
for _, exist := range t.idleConn[key] {
|
for _, exist := range t.idleConn[key] {
|
||||||
@ -569,7 +568,6 @@ func (t *Transport) tryPutIdleConn(pconn *persistConn) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.idleConn[key] = append(t.idleConn[key], pconn)
|
t.idleConn[key] = append(t.idleConn[key], pconn)
|
||||||
t.idleMu.Unlock()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1335,9 +1333,9 @@ type requestAndChan struct {
|
|||||||
req *Request
|
req *Request
|
||||||
ch chan responseAndError // unbuffered; always send in select on callerGone
|
ch chan responseAndError // unbuffered; always send in select on callerGone
|
||||||
|
|
||||||
// did the Transport (as opposed to the client code) add an
|
// whether the Transport (as opposed to the user client code)
|
||||||
// Accept-Encoding gzip header? only if it we set it do
|
// added the Accept-Encoding gzip header. If the Transport
|
||||||
// we transparently decode the gzip.
|
// set it, only then do we transparently decode the gzip.
|
||||||
addedGzip bool
|
addedGzip bool
|
||||||
|
|
||||||
// Optional blocking chan for Expect: 100-continue (for send).
|
// Optional blocking chan for Expect: 100-continue (for send).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user