pester icon indicating copy to clipboard operation
pester copied to clipboard

socket fd leaks if dial timeout occur

Open trulyliu opened this issue 7 years ago • 4 comments

req, err := http.NewRequest("POST", s.url, buffer)
if err != nil {
	return err
}
if s.auth != nil {
	req.SetBasicAuth(s.auth.Login, s.auth.Password)
}

req.Header.Add("Content-Type", "text/xml; charset=\"utf-8\"")
req.Header.Add("SOAPAction", soapAction)
req.Header.Set("User-Agent", "gowsdl/0.1")
req.Close = true

tr := &http.Transport{
	TLSClientConfig: &tls.Config{
		InsecureSkipVerify: s.tls,
	},
	Dial: (&net.Dialer{
		Timeout:   60 * time.Second,
		KeepAlive: 10 * time.Second,
	}).Dial,
	TLSHandshakeTimeout:   5 * time.Second,
	ResponseHeaderTimeout: 300 * time.Second,
	ExpectContinueTimeout: 1 * time.Second,
}

client := &http.Client{Transport: tr}
reliableClient := pester.NewExtendedClient(client)
res, err := reliableClient.Do(req)
if nil != res && nil != res.Body {
	defer res.Body.Close()
}
if err != nil {
	return err
}

If dial timeout occur, opened socket fd will leak. sudo lsof -n -a -p $(pidof processname) |grep "can't identify protocol" |wc -l You will see many 'can't identify protocol' socket.

trulyliu avatar Aug 29 '18 07:08 trulyliu

Thanks for submitting this! I wont have time to dig in this week (PRs welcome!). I can try to dig in this weekend or the next, luck willing.

sethgrid avatar Aug 29 '18 21:08 sethgrid

I've been moving across the country and am super bogged down. I've not forgotten about this, but I don't know when I can get to it. PRs welcome!

sethgrid avatar Nov 20 '18 23:11 sethgrid

Can this still be reproduced? I experimented with dial timeouts on ubuntu today and couldn't reproduce leaked sockets.

Maelkum avatar Aug 10 '20 14:08 Maelkum

To my knowledge, all leaks were patched a while back.

On Mon, Aug 10, 2020 at 8:50 AM Aleksandar Č. [email protected] wrote:

Can this still be reproduced? I experimented with dial timeouts on ubuntu today and couldn't reproduce leaked sockets.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/sethgrid/pester/issues/37*issuecomment-671402203__;Iw!!NCc8flgU!LtYYAX1YaPlf0Ajm5QM6GAG0CoUtSitnhQDwSnO0XVy1gH-MZioVHAJ4Cs2MZBpsKA$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AAHRU7FH5VT42X6RHDJUWMTSAACLFANCNFSM4FSD32OQ__;!!NCc8flgU!LtYYAX1YaPlf0Ajm5QM6GAG0CoUtSitnhQDwSnO0XVy1gH-MZioVHAJ4Cs2q1bXKJA$ .

sethgrid avatar Aug 10 '20 15:08 sethgrid