From 9a58c47922fd0fe545c0c6e9252c467020a94b6f Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 26 Jun 2023 18:42:59 -0700 Subject: [PATCH] http2: revert more of upstream http2 change Even the part we previously kept was bad. Revert all of 82780d60 but keep 6826f5a7db (which depended on bits of 82780d60). So this is a mix. TestTransportRetryAfterRefusedStream fails with this change, but only because it was adjusted in 82780d60 to pass with 82780d60, and this test doesn't revert all the test changes. I just skip that test instead, because it doesn't really affect us. Updates tailscale/corp#12296 Updates golang/go#60818 Signed-off-by: Brad Fitzpatrick --- http2/transport.go | 31 +++++++------------------------ http2/transport_test.go | 1 + 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/http2/transport.go b/http2/transport.go index cc62e6133..862a32736 100644 --- a/http2/transport.go +++ b/http2/transport.go @@ -1266,29 +1266,9 @@ func (cc *ClientConn) RoundTrip(req *http.Request) (*http.Response, error) { return res, nil } - cancelRequest := func(cs *clientStream, markDoNotReuse bool, err error) error { + cancelRequest := func(cs *clientStream, err error) error { cs.cc.mu.Lock() - cs.abortStreamLocked(err) bodyClosed := cs.reqBodyClosed - if markDoNotReuse && 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 - - if f := cs.cc.t.CountError; f != nil { - f("abort_set_do_not_reuse") - log.Printf("ts-http2: set do not reuse: %T, %v", err, err) - } - } cs.cc.mu.Unlock() // Wait for the request body to be closed. // @@ -1323,12 +1303,15 @@ func (cc *ClientConn) RoundTrip(req *http.Request) (*http.Response, error) { return handleResponseHeaders() default: waitDone() - return nil, cancelRequest(cs, true, cs.abortErr) + return nil, cs.abortErr } case <-ctx.Done(): - return nil, cancelRequest(cs, false, ctx.Err()) + err := ctx.Err() + cs.abortStream(err) + return nil, cancelRequest(cs, err) case <-cs.reqCancel: - return nil, cancelRequest(cs, false, errRequestCanceled) + cs.abortStream(errRequestCanceled) + return nil, cancelRequest(cs, errRequestCanceled) } } } diff --git a/http2/transport_test.go b/http2/transport_test.go index 5c659e746..f325c4d4b 100644 --- a/http2/transport_test.go +++ b/http2/transport_test.go @@ -3857,6 +3857,7 @@ func TestTransportRetryAfterGOAWAY(t *testing.T) { } func TestTransportRetryAfterRefusedStream(t *testing.T) { + t.Skip("broken by 82780d60 and later reverts; see https://github.com/golang/go/issues/60818 and https://github.com/tailscale/corp/issues/12296") clientDone := make(chan struct{}) client := func(tr *Transport) { defer close(clientDone)