requests to a url to check whether proxies are available. Here is a part
of my checker code, the check proxy function:
func checkProxy(proxy string, timeout int) bool {
proxyUrl, err := url.Parse("http://" + proxy)
httpClient := &http.Client{
Transport: &http.Transport{httpClient := &http.Client{
Proxy: http.ProxyURL(proxyUrl),
Dial: func(netw, addr string) (net.Conn, error) {
deadline := time.Now().Add(time.Duration(timeout) * time.Second)
c, err := net.DialTimeout(netw, addr, time.Second*time.Duration(timeout))
if err != nil {
return nil, err
}
c.SetDeadline(deadline)
return c, nil
},
ResponseHeaderTimeout: time.Duration(timeout) * time.Second,
DisableKeepAlives: true,
},
}
req, err := http.NewRequest("GET", "http://www.urltocheck.com", nil)
req.Close = true
resp, err := httpClient.Do(req)req.Close = true
if err != nil {
return false
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
if strings.Contains(string(body), "xxx") {return true
} else {
return false
}
}
these two writeLoop and readLoop goroutines keep growing, the longer i run
the checker, the more they are (could be more than ten thousands):
8054 @ 0x41a716 0x4080d4 0x407d22 0x488021 0x41a8e0
# 0x4080d4 selectgo+0x384 /usr/local/go/src/pkg/runtime/chan.c:996
# 0x407d22 runtime.selectgo+0x12 /usr/local/go/src/pkg/runtime/chan.c:840
# 0x488021 net/http.(*persistConn).writeLoop+0x271 /usr/local/go/src/pkg/net/http/transport.go:791
8030 @ 0x41a716 0x4072d2 0x407718 0x4879cf 0x41a8e0
# 0x4879cf net/http.(*persistConn).readLoop+0x68f /usr/local/go/src/pkg/net/http/transport.go:778
And my memory leaks so bad, I find a bug been reports two years ago
https://code.google.com/p/go/issues/detail?id=4531 (net/http: Transport
leaks goroutines when request.ContentLength is explicitly short) which had
been marked fixed, but I think somewhere someplace transport still leaking.
Anyone would help, thanks a lot!
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.