Commit d0402cb4 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http/httputil: don't leak goroutines in DumpRequestOut

Fixes #7869

LGTM=dsymonds
R=golang-codereviews
CC=adg, dsymonds, golang-codereviews, rsc
https://golang.org/cl/91770048
parent e419ab64
......@@ -107,6 +107,7 @@ func DumpRequestOut(req *http.Request, body bool) ([]byte, error) {
return &dumpConn{io.MultiWriter(&buf, pw), dr}, nil
},
}
defer t.CloseIdleConnections()
_, err := t.RoundTrip(reqSend)
......
......@@ -11,6 +11,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
"runtime"
"strings"
"testing"
)
......@@ -113,6 +114,7 @@ var dumpTests = []dumpTest{
}
func TestDumpRequest(t *testing.T) {
numg0 := runtime.NumGoroutine()
for i, tt := range dumpTests {
setBody := func() {
if tt.Body == nil {
......@@ -156,6 +158,9 @@ func TestDumpRequest(t *testing.T) {
}
}
}
if dg := runtime.NumGoroutine() - numg0; dg > 4 {
t.Errorf("Unexpectedly large number of new goroutines: %d new", dg)
}
}
func chunk(s string) string {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment