From 79861be2059e014ca0647de3be22e7c341e61e20 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Wed, 16 Mar 2022 18:04:43 -0400 Subject: 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 Run-TryBot: Heschi Kreinick Auto-Submit: Heschi Kreinick Reviewed-by: Dmitri Shuralyov TryBot-Result: Gopher Robot --- src/net/http/h2_bundle.go | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'src/net/http') 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 { -- cgit v1.3-5-g9baa