From: Damien Neil Date: Wed, 14 Dec 2022 23:49:58 +0000 (-0800) Subject: net/http: improve errors in TestCancelRequestWhenSharingConnection X-Git-Tag: go1.20rc2~1^2~21 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f4b42f5cb8;p=gostls13.git net/http: improve errors in TestCancelRequestWhenSharingConnection Provide more information about why this test might be hanging waiting for PutIdleConn to be called (#56587): If the round trip that should result in PutIdleConn being invoked completes, report that to the goroutine waiting for PutIdleConn. For #56587 Change-Id: Ie476ea0ce4a48d2bda6b9b109f89d675a10e7e45 Reviewed-on: https://go-review.googlesource.com/c/go/+/457775 Auto-Submit: Damien Neil TryBot-Result: Gopher Robot Run-TryBot: Damien Neil Reviewed-by: Bryan Mills --- diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index 2bc83fd42b..245f73bc9f 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -6565,7 +6565,8 @@ func testCancelRequestWhenSharingConnection(t *testing.T, mode testMode) { var wg sync.WaitGroup wg.Add(1) - putidlec := make(chan chan struct{}) + putidlec := make(chan chan struct{}, 1) + reqerrc := make(chan error, 1) go func() { defer wg.Done() ctx := httptrace.WithClientTrace(context.Background(), &httptrace.ClientTrace{ @@ -6574,24 +6575,31 @@ func testCancelRequestWhenSharingConnection(t *testing.T, mode testMode) { // and wait for the order to proceed. ch := make(chan struct{}) putidlec <- ch + close(putidlec) // panic if PutIdleConn runs twice for some reason <-ch }, }) req, _ := NewRequestWithContext(ctx, "GET", ts.URL, nil) res, err := client.Do(req) + reqerrc <- err if err == nil { res.Body.Close() } - if err != nil { - t.Errorf("request 1: got err %v, want nil", err) - } }() // Wait for the first request to receive a response and return the // connection to the idle pool. r1c := <-reqc close(r1c) - idlec := <-putidlec + var idlec chan struct{} + select { + case err := <-reqerrc: + if err != nil { + t.Fatalf("request 1: got err %v, want nil", err) + } + idlec = <-putidlec + case idlec = <-putidlec: + } wg.Add(1) cancelctx, cancel := context.WithCancel(context.Background())