From: Michael Fraenkel Date: Thu, 13 May 2021 15:41:45 +0000 (-0600) Subject: [release-branch.go1.16] net/http: prevent infinite wait during TestMissingStatusNoPanic X-Git-Tag: go1.16.5~6 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1613be84815e34b2c803694ac073b2ae67f18168;p=gostls13.git [release-branch.go1.16] net/http: prevent infinite wait during TestMissingStatusNoPanic If the client request never makes it to the server, the outstanding accept is never broken. Change the test to always close the listening socket when the client request completes. Updates #45358 Change-Id: I744a91dfa11704e7e528163d7669c394e90456dc Reviewed-on: https://go-review.googlesource.com/c/go/+/319275 Trust: Heschi Kreinick Reviewed-by: Bryan C. Mills (cherry picked from commit c0a7ecfae775a9d50d338e8123fac32a5d04308c) Reviewed-on: https://go-review.googlesource.com/c/go/+/320190 Reviewed-by: Damien Neil Run-TryBot: Bryan C. Mills TryBot-Result: Go Bot --- diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index ba85a61683..73d259dc9a 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -5314,7 +5314,6 @@ func TestMissingStatusNoPanic(t *testing.T) { ln := newLocalListener(t) addr := ln.Addr().String() - shutdown := make(chan bool, 1) done := make(chan bool) fullAddrURL := fmt.Sprintf("http://%s", addr) raw := "HTTP/1.1 400\r\n" + @@ -5326,10 +5325,7 @@ func TestMissingStatusNoPanic(t *testing.T) { "Aloha Olaa" go func() { - defer func() { - ln.Close() - close(done) - }() + defer close(done) conn, _ := ln.Accept() if conn != nil { @@ -5360,7 +5356,7 @@ func TestMissingStatusNoPanic(t *testing.T) { t.Errorf("got=%v want=%q", err, want) } - close(shutdown) + ln.Close() <-done }