Skip to content

Commit

Permalink
net/http: avoid leaking io.Copy goroutines (and hijacked connections)…
Browse files Browse the repository at this point in the history
… 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>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed Dec 1, 2023
1 parent 3220bbe commit 58bfef8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/net/http/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3499,6 +3499,7 @@ func testTransportNoReuseAfterEarlyResponse(t *testing.T, mode testMode) {
c net.Conn
}
var getOkay bool
var copying sync.WaitGroup
closeConn := func() {
sconn.Lock()
defer sconn.Unlock()
Expand All @@ -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) {
if r.Method == "GET" {
Expand All @@ -3522,7 +3526,12 @@ func testTransportNoReuseAfterEarlyResponse(t *testing.T, mode testMode) {
sconn.c = conn
sconn.Unlock()
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
c := ts.Client()

Expand Down

0 comments on commit 58bfef8

Please sign in to comment.