Skip to content

Commit ecb0f58

Browse files
authored
Merge pull request #40 from ppiaas/master
fix excessive amount of connections ending up in TIME_WAIT
2 parents de90a0d + 17f7dd2 commit ecb0f58

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

client.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/base64"
88
"encoding/json"
99
"fmt"
10+
"net"
1011
"net/http"
1112
"net/url"
1213
"reflect"
@@ -30,6 +31,23 @@ var (
3031
contextType = reflect.TypeOf(new(context.Context)).Elem()
3132

3233
log = logging.Logger("rpc")
34+
35+
_defaultHTTPClient = &http.Client{
36+
Transport: &http.Transport{
37+
Proxy: http.ProxyFromEnvironment,
38+
DialContext: (&net.Dialer{
39+
Timeout: 30 * time.Second,
40+
KeepAlive: 30 * time.Second,
41+
DualStack: true,
42+
}).DialContext,
43+
ForceAttemptHTTP2: true,
44+
MaxIdleConns: 100,
45+
MaxIdleConnsPerHost: 100,
46+
IdleConnTimeout: 90 * time.Second,
47+
TLSHandshakeTimeout: 10 * time.Second,
48+
ExpectContinueTimeout: 1 * time.Second,
49+
},
50+
}
3351
)
3452

3553
// ErrClient is an error which occurred on the client side the library
@@ -140,7 +158,7 @@ func httpClient(ctx context.Context, addr string, namespace string, outs []inter
140158

141159
hreq.Header.Set("Content-Type", "application/json")
142160

143-
httpResp, err := http.DefaultClient.Do(hreq)
161+
httpResp, err := _defaultHTTPClient.Do(hreq)
144162
if err != nil {
145163
return clientResponse{}, err
146164
}

0 commit comments

Comments
 (0)