Skip to content

Commit aa996cd

Browse files
author
Dieter Plaetinck
committed
prevent "use of closed network connection" in graphite GET's
I would sometimes see errors like: graphiteBand: graphite RequestError (http://....): Get failed: Get http://... : read tcp 10.90.128.100:80: use of closed network connection This kind of error is not something that should bubble up to the caller of a http client library, but it does. see also: golang/go#8946 golang/go#9424 there's a bunch more issues about the broken state of error handling in net/http. So anyway the http client tries to reuse an existing connection which has broken. Somehow this is the caller's problem, so we address it by not keeping any idle connection and opening a new connection each time. This should get rid of these errors without adding much overhead. Note that the used http transport is, other than the MaxIdleConnsPerHost setting, the same as the default transport.
1 parent d23314b commit aa996cd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

graphite/graphite.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"io/ioutil"
8+
"net"
89
"net/http"
910
"net/url"
1011
"strings"
@@ -100,6 +101,15 @@ func readTraceback(resp *http.Response) (*[]string, error) {
100101
// DefaultClient is the default HTTP client for requests.
101102
var DefaultClient = &http.Client{
102103
Timeout: time.Minute,
104+
Transport: &http.Transport{
105+
MaxIdleConnsPerHost: 0,
106+
Proxy: http.ProxyFromEnvironment,
107+
Dial: (&net.Dialer{
108+
Timeout: 30 * time.Second,
109+
KeepAlive: 30 * time.Second,
110+
}).Dial,
111+
TLSHandshakeTimeout: 10 * time.Second,
112+
},
103113
}
104114

105115
// Context is the interface for querying a Graphite server.

0 commit comments

Comments
 (0)