From 275be3f2e8c731d21ec540ee52613572697c1653 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Wed, 13 Oct 2021 10:29:31 -0700 Subject: [PATCH] [internal-branch.go1.16-vendor] http2: deflake TestTransportReqBodyAfterResponse_200 Don't send the END_STREAM flag from the server until the client sends its END_STREAM. Avoids a flaky failure when the client sends the END_STREAM in a zero-length DATA frame: - The server reads bodySize bytes and half-closes the stream. - The client's Response.Body returns EOF. - The test calls Response.Body.Close. - The client resets the stream. Avoid hanging forever on the client side of the test if the server side exits with an error. Updates golang/go#49076 Change-Id: Ic921a3f60149abbb5434ec7a53985becea7b23c3 Reviewed-on: https://go-review.googlesource.com/c/net/+/355649 Trust: Damien Neil Reviewed-by: Bryan C. Mills Reviewed-on: https://go-review.googlesource.com/c/net/+/357096 Run-TryBot: Damien Neil Reviewed-by: Dmitri Shuralyov TryBot-Result: Go Bot --- http2/transport_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/http2/transport_test.go b/http2/transport_test.go index f04a1b01b5..864cee7ccd 100644 --- a/http2/transport_test.go +++ b/http2/transport_test.go @@ -934,6 +934,7 @@ func testTransportReqBodyAfterResponse(t *testing.T, status int) { } ct.server = func() error { ct.greet() + defer close(recvLen) var buf bytes.Buffer enc := hpack.NewEncoder(&buf) var dataRecv int64 @@ -984,7 +985,7 @@ func testTransportReqBodyAfterResponse(t *testing.T, status int) { dataRecv += int64(dataLen) if !closed && ((status != 200 && dataRecv > 0) || - (status == 200 && dataRecv == bodySize)) { + (status == 200 && f.StreamEnded())) { closed = true if err := ct.fr.WriteData(f.StreamID, true, nil); err != nil { return err