Skip to content

Commit 58bfef8

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
net/http: avoid leaking io.Copy goroutines (and hijacked connections) in TestTransportNoReuseAfterEarlyResponse
Fixes #64252 (maybe). Change-Id: Iba2a403a9347be4206f14acb11591dc2eb7f9fb8 Reviewed-on: https://go-review.googlesource.com/c/go/+/546616 Reviewed-by: Damien Neil <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Bryan Mills <[email protected]>
1 parent 3220bbe commit 58bfef8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/net/http/transport_test.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -3499,6 +3499,7 @@ func testTransportNoReuseAfterEarlyResponse(t *testing.T, mode testMode) {
34993499
c net.Conn
35003500
}
35013501
var getOkay bool
3502+
var copying sync.WaitGroup
35023503
closeConn := func() {
35033504
sconn.Lock()
35043505
defer sconn.Unlock()
@@ -3510,7 +3511,10 @@ func testTransportNoReuseAfterEarlyResponse(t *testing.T, mode testMode) {
35103511
}
35113512
}
35123513
}
3513-
defer closeConn()
3514+
defer func() {
3515+
closeConn()
3516+
copying.Wait()
3517+
}()
35143518

35153519
ts := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
35163520
if r.Method == "GET" {
@@ -3522,7 +3526,12 @@ func testTransportNoReuseAfterEarlyResponse(t *testing.T, mode testMode) {
35223526
sconn.c = conn
35233527
sconn.Unlock()
35243528
conn.Write([]byte("HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nfoo")) // keep-alive
3525-
go io.Copy(io.Discard, conn)
3529+
3530+
copying.Add(1)
3531+
go func() {
3532+
io.Copy(io.Discard, conn)
3533+
copying.Done()
3534+
}()
35263535
})).ts
35273536
c := ts.Client()
35283537

0 commit comments

Comments
 (0)