Skip to content
This repository was archived by the owner on Sep 13, 2021. It is now read-only.

Commit e5afeec

Browse files
committed
Fix timeout and keepalive by using Client.Timeout
With net.Conn.SetDeadline the connection could not be reused for additional requests after the timeout, and even a fast response could time out while reading, because the timer was started by a previous request. With a five second scrape interval, the log will fill up with this error: ERRO[0108] Unexpected error while reading CSV: read tcp n.n.n.n:57648->m.m.m.m:443: i/o timeout source=haproxy_exporter.go:331 With this change I can not see any more errors and by using netstat I can see that the same port/connection is reused for a while.
1 parent 9dbb360 commit e5afeec

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

haproxy_exporter.go

+1-12
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,7 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
249249

250250
func fetchHTTP(uri string, timeout time.Duration) func() (io.ReadCloser, error) {
251251
client := http.Client{
252-
Transport: &http.Transport{
253-
Dial: func(netw, addr string) (net.Conn, error) {
254-
c, err := net.DialTimeout(netw, addr, timeout)
255-
if err != nil {
256-
return nil, err
257-
}
258-
if err := c.SetDeadline(time.Now().Add(timeout)); err != nil {
259-
return nil, err
260-
}
261-
return c, nil
262-
},
263-
},
252+
Timeout: timeout,
264253
}
265254

266255
return func() (io.ReadCloser, error) {

0 commit comments

Comments
 (0)