Skip to content

socket fd leaks if dial timeout occur #37

@trulyliu

Description

@trulyliu
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions