mirror of https://github.com/prometheus/prometheus
Browse Source
Instead of externally handling timeouts when scraping a target, we set timeouts on the HTTP connection. This ensures that we don't leak goroutines on timeouts. [fixes #181]pull/196/head
Bernerd Schaefer
12 years ago
3 changed files with 112 additions and 58 deletions
@ -0,0 +1,30 @@
|
||||
package retrieval |
||||
|
||||
import ( |
||||
"net" |
||||
"net/http" |
||||
"time" |
||||
) |
||||
|
||||
// NewDeadlineClient returns a new http.Client which will time out long running
|
||||
// requests.
|
||||
func NewDeadlineClient(timeout time.Duration) http.Client { |
||||
return http.Client{ |
||||
Transport: &http.Transport{ |
||||
// We need to disable keepalive, becasue we set a deadline on the
|
||||
// underlying connection.
|
||||
DisableKeepAlives: true, |
||||
Dial: func(netw, addr string) (c net.Conn, err error) { |
||||
start := time.Now() |
||||
|
||||
c, err = net.DialTimeout(netw, addr, timeout) |
||||
|
||||
if err == nil { |
||||
c.SetDeadline(start.Add(timeout)) |
||||
} |
||||
|
||||
return |
||||
}, |
||||
}, |
||||
} |
||||
} |
Loading…
Reference in new issue