From d8ab19b2f2d754e374af7fc643dac5224667310b Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Tue, 9 May 2023 09:00:02 -0400 Subject: [PATCH] net/http: regenerate h2_bundle.go The x/net version was updated in CL 493596; cmd/internal/moddeps catches the skew, but only runs on the -longtest builders (because it requires network access for the bundle tool and x/net dependency). Change-Id: I48891d51aab23b2ca6f4484215438c60bd8c8c21 Reviewed-on: https://go-review.googlesource.com/c/go/+/493875 TryBot-Result: Gopher Robot Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills Reviewed-by: Alan Donovan --- src/net/http/h2_bundle.go | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/net/http/h2_bundle.go b/src/net/http/h2_bundle.go index 8ec90cdabb..ed8d53ab3b 100644 --- a/src/net/http/h2_bundle.go +++ b/src/net/http/h2_bundle.go @@ -8287,6 +8287,27 @@ func (cc *http2ClientConn) RoundTrip(req *Request) (*Response, error) { return res, nil } + cancelRequest := func(cs *http2clientStream, err error) error { + cs.cc.mu.Lock() + defer cs.cc.mu.Unlock() + cs.abortStreamLocked(err) + if cs.ID != 0 { + // This request may have failed because of a problem with the connection, + // or for some unrelated reason. (For example, the user might have canceled + // the request without waiting for a response.) Mark the connection as + // not reusable, since trying to reuse a dead connection is worse than + // unnecessarily creating a new one. + // + // If cs.ID is 0, then the request was never allocated a stream ID and + // whatever went wrong was unrelated to the connection. We might have + // timed out waiting for a stream slot when StrictMaxConcurrentStreams + // is set, for example, in which case retrying on a different connection + // will not help. + cs.cc.doNotReuse = true + } + return err + } + for { select { case <-cs.respHeaderRecv: @@ -8301,15 +8322,12 @@ func (cc *http2ClientConn) RoundTrip(req *Request) (*Response, error) { return handleResponseHeaders() default: waitDone() - return nil, cs.abortErr + return nil, cancelRequest(cs, cs.abortErr) } case <-ctx.Done(): - err := ctx.Err() - cs.abortStream(err) - return nil, err + return nil, cancelRequest(cs, ctx.Err()) case <-cs.reqCancel: - cs.abortStream(http2errRequestCanceled) - return nil, http2errRequestCanceled + return nil, cancelRequest(cs, http2errRequestCanceled) } } } -- 2.50.0