mirror of
https://github.com/golang/go.git
synced 2025-05-19 14:24:46 +00:00
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 <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
3220bbe1fb
commit
58bfef82fc
@ -3499,6 +3499,7 @@ func testTransportNoReuseAfterEarlyResponse(t *testing.T, mode testMode) {
|
|||||||
c net.Conn
|
c net.Conn
|
||||||
}
|
}
|
||||||
var getOkay bool
|
var getOkay bool
|
||||||
|
var copying sync.WaitGroup
|
||||||
closeConn := func() {
|
closeConn := func() {
|
||||||
sconn.Lock()
|
sconn.Lock()
|
||||||
defer sconn.Unlock()
|
defer sconn.Unlock()
|
||||||
@ -3510,7 +3511,10 @@ func testTransportNoReuseAfterEarlyResponse(t *testing.T, mode testMode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defer closeConn()
|
defer func() {
|
||||||
|
closeConn()
|
||||||
|
copying.Wait()
|
||||||
|
}()
|
||||||
|
|
||||||
ts := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
|
ts := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
@ -3522,7 +3526,12 @@ func testTransportNoReuseAfterEarlyResponse(t *testing.T, mode testMode) {
|
|||||||
sconn.c = conn
|
sconn.c = conn
|
||||||
sconn.Unlock()
|
sconn.Unlock()
|
||||||
conn.Write([]byte("HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nfoo")) // keep-alive
|
conn.Write([]byte("HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nfoo")) // keep-alive
|
||||||
go io.Copy(io.Discard, conn)
|
|
||||||
|
copying.Add(1)
|
||||||
|
go func() {
|
||||||
|
io.Copy(io.Discard, conn)
|
||||||
|
copying.Done()
|
||||||
|
}()
|
||||||
})).ts
|
})).ts
|
||||||
c := ts.Client()
|
c := ts.Client()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user