This commit is contained in:
Eugene Bujak 2019-02-07 14:45:46 +03:00
parent bb8d7c37bb
commit f9d1948f6a

View file

@ -892,15 +892,16 @@ func New(c *Config) *Dnsfilter {
d.whiteList = newRulesTable() d.whiteList = newRulesTable()
d.blackList = newRulesTable() d.blackList = newRulesTable()
// Customize the Transport to have larger connection pool // Customize the Transport to have larger connection pool,
defaultRoundTripper := http.DefaultTransport // We are not (re)using http.DefaultTransport because of race conditions found by tests
defaultTransportPointer, ok := defaultRoundTripper.(*http.Transport) d.transport = &http.Transport{
if !ok { Proxy: http.ProxyFromEnvironment,
panic(fmt.Sprintf("defaultRoundTripper not an *http.Transport")) MaxIdleConns: defaultHTTPMaxIdleConnections, // default 100
MaxIdleConnsPerHost: defaultHTTPMaxIdleConnections, // default 2
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
} }
d.transport = defaultTransportPointer // dereference it to get a copy of the struct that the pointer points to
d.transport.MaxIdleConns = defaultHTTPMaxIdleConnections // default 100
d.transport.MaxIdleConnsPerHost = defaultHTTPMaxIdleConnections // default 2
d.client = http.Client{ d.client = http.Client{
Transport: d.transport, Transport: d.transport,
Timeout: defaultHTTPTimeout, Timeout: defaultHTTPTimeout,