From ef4b2fdc48f242fe8f95f15df055c674efa8f35e Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Thu, 6 Apr 2023 12:09:04 -0700 Subject: [PATCH] net/http: improve failure mode for TestResponseControllerSetPastReadDeadline A test flake in #59447 seems to indicate that this test got stuck waiting for the test handler to close the readc channel. If the handler returns early due to an unexpected error, it might fail to close this channel. Add a second channel to act as a signal that the handler has given up and the test should stop. This won't fix whatever happened in the flake, but might help us debug it if it happens again. For #59447 Change-Id: I05d84c6176aa938887d93126a6f3bb4dc941c90d Reviewed-on: https://go-review.googlesource.com/c/go/+/482935 Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Auto-Submit: Damien Neil Run-TryBot: Damien Neil --- src/net/http/responsecontroller_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/net/http/responsecontroller_test.go b/src/net/http/responsecontroller_test.go index ee8b55a89f..c560e4bc54 100644 --- a/src/net/http/responsecontroller_test.go +++ b/src/net/http/responsecontroller_test.go @@ -156,7 +156,9 @@ func TestResponseControllerSetPastReadDeadline(t *testing.T) { } func testResponseControllerSetPastReadDeadline(t *testing.T, mode testMode) { readc := make(chan struct{}) + donec := make(chan struct{}) cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) { + defer close(donec) ctl := NewResponseController(w) b := make([]byte, 3) n, err := io.ReadFull(r.Body, b) @@ -192,10 +194,15 @@ func testResponseControllerSetPastReadDeadline(t *testing.T, mode testMode) { wg.Add(1) go func() { defer wg.Done() + defer pw.Close() pw.Write([]byte("one")) - <-readc + select { + case <-readc: + case <-donec: + t.Errorf("server handler unexpectedly exited without closing readc") + return + } pw.Write([]byte("two")) - pw.Close() }() defer wg.Wait() res, err := cst.c.Post(cst.ts.URL, "text/foo", pr) -- 2.48.1