aboutsummaryrefslogtreecommitdiff
path: root/src/net/http
diff options
context:
space:
mode:
authorHeschi Kreinick <heschi@google.com>2022-03-16 18:04:43 -0400
committerGopher Robot <gobot@golang.org>2022-03-17 20:32:25 +0000
commit79861be2059e014ca0647de3be22e7c341e61e20 (patch)
treee0687c76932dcc84d8b067f7363a8d1906e8a97e /src/net/http
parent3046ae927d7664a63bb8c3a2fb3b9ca95bcf93de (diff)
downloadgo-79861be2059e014ca0647de3be22e7c341e61e20.tar.xz
all: update vendored x dependencies for Go 1.19 development cycle
Generated with x/build/cmd/updatestd. Updates #36905. Change-Id: I5d12dfc3b49c1476ce4b8d4cbeb35bd3d3443d26 Reviewed-on: https://go-review.googlesource.com/c/go/+/393369 Trust: Heschi Kreinick <heschi@google.com> Run-TryBot: Heschi Kreinick <heschi@google.com> Auto-Submit: Heschi Kreinick <heschi@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/net/http')
-rw-r--r--src/net/http/h2_bundle.go47
1 files changed, 34 insertions, 13 deletions
diff --git a/src/net/http/h2_bundle.go b/src/net/http/h2_bundle.go
index bb82f24585..e955135c50 100644
--- a/src/net/http/h2_bundle.go
+++ b/src/net/http/h2_bundle.go
@@ -3010,6 +3010,10 @@ func (t *http2Transport) dialTLSWithContext(ctx context.Context, network, addr s
return tlsCn, nil
}
+func http2tlsUnderlyingConn(tc *tls.Conn) net.Conn {
+ return tc.NetConn()
+}
+
var http2DebugGoroutines = os.Getenv("DEBUG_HTTP2_GOROUTINES") == "1"
type http2goroutineLock uint64
@@ -4439,7 +4443,7 @@ func (sc *http2serverConn) canonicalHeader(v string) string {
// maxCachedCanonicalHeaders is an arbitrarily-chosen limit on the number of
// entries in the canonHeader cache. This should be larger than the number
// of unique, uncommon header keys likely to be sent by the peer, while not
- // so high as to permit unreaasonable memory usage if the peer sends an unbounded
+ // so high as to permit unreasonable memory usage if the peer sends an unbounded
// number of unique header keys.
const maxCachedCanonicalHeaders = 32
if len(sc.canonHeader) < maxCachedCanonicalHeaders {
@@ -7449,7 +7453,6 @@ func (cc *http2ClientConn) healthCheck() {
err := cc.Ping(ctx)
if err != nil {
cc.closeForLostPing()
- cc.t.connPool().MarkDead(cc)
return
}
}
@@ -7621,6 +7624,24 @@ func (cc *http2ClientConn) onIdleTimeout() {
cc.closeIfIdle()
}
+func (cc *http2ClientConn) closeConn() error {
+ t := time.AfterFunc(250*time.Millisecond, cc.forceCloseConn)
+ defer t.Stop()
+ return cc.tconn.Close()
+}
+
+// A tls.Conn.Close can hang for a long time if the peer is unresponsive.
+// Try to shut it down more aggressively.
+func (cc *http2ClientConn) forceCloseConn() {
+ tc, ok := cc.tconn.(*tls.Conn)
+ if !ok {
+ return
+ }
+ if nc := http2tlsUnderlyingConn(tc); nc != nil {
+ nc.Close()
+ }
+}
+
func (cc *http2ClientConn) closeIfIdle() {
cc.mu.Lock()
if len(cc.streams) > 0 || cc.streamsReserved > 0 {
@@ -7635,7 +7656,7 @@ func (cc *http2ClientConn) closeIfIdle() {
if http2VerboseLogs {
cc.vlogf("http2: Transport closing idle conn %p (forSingleUse=%v, maxStream=%v)", cc, cc.singleUse, nextID-2)
}
- cc.tconn.Close()
+ cc.closeConn()
}
func (cc *http2ClientConn) isDoNotReuseAndIdle() bool {
@@ -7652,7 +7673,7 @@ func (cc *http2ClientConn) Shutdown(ctx context.Context) error {
return err
}
// Wait for all in-flight streams to complete or connection to close
- done := make(chan error, 1)
+ done := make(chan struct{})
cancelled := false // guarded by cc.mu
go func() {
cc.mu.Lock()
@@ -7660,7 +7681,7 @@ func (cc *http2ClientConn) Shutdown(ctx context.Context) error {
for {
if len(cc.streams) == 0 || cc.closed {
cc.closed = true
- done <- cc.tconn.Close()
+ close(done)
break
}
if cancelled {
@@ -7671,8 +7692,8 @@ func (cc *http2ClientConn) Shutdown(ctx context.Context) error {
}()
http2shutdownEnterWaitStateHook()
select {
- case err := <-done:
- return err
+ case <-done:
+ return cc.closeConn()
case <-ctx.Done():
cc.mu.Lock()
// Free the goroutine above
@@ -7715,9 +7736,9 @@ func (cc *http2ClientConn) closeForError(err error) error {
for _, cs := range cc.streams {
cs.abortStreamLocked(err)
}
- defer cc.cond.Broadcast()
- defer cc.mu.Unlock()
- return cc.tconn.Close()
+ cc.cond.Broadcast()
+ cc.mu.Unlock()
+ return cc.closeConn()
}
// Close closes the client connection immediately.
@@ -8692,7 +8713,7 @@ func (cc *http2ClientConn) forgetStreamID(id uint32) {
cc.vlogf("http2: Transport closing idle conn %p (forSingleUse=%v, maxStream=%v)", cc, cc.singleUse, cc.nextStreamID-2)
}
cc.closed = true
- defer cc.tconn.Close()
+ defer cc.closeConn()
}
cc.mu.Unlock()
@@ -8739,8 +8760,8 @@ func http2isEOFOrNetReadError(err error) bool {
func (rl *http2clientConnReadLoop) cleanup() {
cc := rl.cc
- defer cc.tconn.Close()
- defer cc.t.connPool().MarkDead(cc)
+ cc.t.connPool().MarkDead(cc)
+ defer cc.closeConn()
defer close(cc.readerDone)
if cc.idleTimer != nil {