Skip to content

Commit f4b42f5

Browse files
neildgopherbot
authored andcommitted
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Damien Neil <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent 24ac659 commit f4b42f5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/net/http/transport_test.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -6565,7 +6565,8 @@ func testCancelRequestWhenSharingConnection(t *testing.T, mode testMode) {
65656565
var wg sync.WaitGroup
65666566

65676567
wg.Add(1)
6568-
putidlec := make(chan chan struct{})
6568+
putidlec := make(chan chan struct{}, 1)
6569+
reqerrc := make(chan error, 1)
65696570
go func() {
65706571
defer wg.Done()
65716572
ctx := httptrace.WithClientTrace(context.Background(), &httptrace.ClientTrace{
@@ -6574,24 +6575,31 @@ func testCancelRequestWhenSharingConnection(t *testing.T, mode testMode) {
65746575
// and wait for the order to proceed.
65756576
ch := make(chan struct{})
65766577
putidlec <- ch
6578+
close(putidlec) // panic if PutIdleConn runs twice for some reason
65776579
<-ch
65786580
},
65796581
})
65806582
req, _ := NewRequestWithContext(ctx, "GET", ts.URL, nil)
65816583
res, err := client.Do(req)
6584+
reqerrc <- err
65826585
if err == nil {
65836586
res.Body.Close()
65846587
}
6585-
if err != nil {
6586-
t.Errorf("request 1: got err %v, want nil", err)
6587-
}
65886588
}()
65896589

65906590
// Wait for the first request to receive a response and return the
65916591
// connection to the idle pool.
65926592
r1c := <-reqc
65936593
close(r1c)
6594-
idlec := <-putidlec
6594+
var idlec chan struct{}
6595+
select {
6596+
case err := <-reqerrc:
6597+
if err != nil {
6598+
t.Fatalf("request 1: got err %v, want nil", err)
6599+
}
6600+
idlec = <-putidlec
6601+
case idlec = <-putidlec:
6602+
}
65956603

65966604
wg.Add(1)
65976605
cancelctx, cancel := context.WithCancel(context.Background())

0 commit comments

Comments
 (0)