Skip to content

Commit abee42a

Browse files
committed
http2: deflake TestTransportReuseAfterError
This test issues a request with a short timeout, and expects that the request timing out will result in the connection it was sent on being marked as unusable. However, it is possible for the request to time out before it is sent, with no effect on the connection. The test's next request then uses the same connection and hangs. Rather than a timeout, cancel the request after it is received on the server. Fixes golang/go#59934 Change-Id: I1144686377158d0654e0f91a1b0312021a02a01d Reviewed-on: https://go-review.googlesource.com/c/net/+/496055 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
1 parent 3b31286 commit abee42a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

http2/transport_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6434,15 +6434,17 @@ func TestTransportReuseAfterError(t *testing.T) {
64346434

64356435
// Request 2 is also made on conn 1.
64366436
// Reading the response will block.
6437-
// The request fails when the context deadline expires.
6437+
// The request is canceled once the server receives it.
64386438
// Conn 1 should now be flagged as unfit for reuse.
6439-
timeoutCtx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
6440-
defer cancel()
6441-
_, err := tr.RoundTrip(req.Clone(timeoutCtx))
6439+
req2Ctx, cancel := context.WithCancel(context.Background())
6440+
go func() {
6441+
<-serverReqc
6442+
cancel()
6443+
}()
6444+
_, err := tr.RoundTrip(req.Clone(req2Ctx))
64426445
if err == nil {
6443-
t.Errorf("request 2 unexpectedly succeeded (want timeout)")
6446+
t.Errorf("request 2 unexpectedly succeeded (want cancel)")
64446447
}
6445-
time.Sleep(1 * time.Millisecond)
64466448

64476449
// Request 3 is made on a new conn, and succeeds.
64486450
res3, err := tr.RoundTrip(req.Clone(context.Background()))

0 commit comments

Comments
 (0)