UPDATED CODE
Hi I have memory leaks in httpClient, i've added sync.WaitGroup and now I see that goroutine with httpClient don't closed. How to fix it?
func checkProxySOCKS(prox string, c chan QR, wg *sync.WaitGroup) (err error) {
defer wg.Done()
dialer, _ := proxy.SOCKS5("tcp", prox, nil, proxy.Direct)
timeout := time.Duration(2 * time.Second)
httpClient := &http.Client{
Timeout: timeout,
Transport: &http.Transport{
DisableKeepAlives: true,
Dial: dialer.Dial,
},
}
res, err := httpClient.Get("https://telegram.org/")
if err != nil {
c <- QR{Addr: prox, Res: false}
return
}
defer res.Body.Close()
io.Copy(ioutil.Discard, res.Body)
c <- QR{Addr: prox, Res: true}
return nil
} Here i create goroutines
for _, proxy := range splitedProxies {
wg.Add(1)
go checkProxySOCKS(proxy, respChan, &wg)
}
for range splitedProxies {
wg.Add(1)
r := <-respChan
if r.Res {
checkedProxiesArray = append(checkedProxiesArray, r.Addr)
}
wg.Done()
}
wg.Wait()