UPD: Refactored code, nothing change
I'm have memory leak in this function but i don't know where.
func CheckProxySOCKS(prox string, c chan QR) (err error) {
//Sending request through proxy
dialer, _ := proxy.SOCKS5("tcp", prox, nil, proxy.Direct)
timeout := time.Duration(5 * time.Second)
httpClient := &http.Client{Timeout: timeout, Transport: &http.Transport{Dial: dialer.Dial}}
res, err := httpClient.Get("https://api.ipify.org?format=json")
if err != nil {
c <- QR{Addr: prox, Res: false}
return
}
_, err = ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return
}
c <- QR{Addr: prox, Res: true}
return
}
Here i called it
for _, proxy := range splitedProxies {
go code.CheckProxySOCKS(proxy, respChan)
}
for range splitedProxies {
r := <-respChan
if r.Res {
checkedProxiesArray = append(checkedProxiesArray, r.Addr)
}
}
After 3-4 cycle i'v got more than 40k goroutines(i'v check it by runtime.NumGoroutine()
). After start app used around 100mb after 4 cycle more than 1GB
Github repo with all code