Compare commits

...

3 Commits

Author SHA1 Message Date
Star Brilliant
93b70f3941 Release 1.3.5 2018-04-27 00:39:48 +08:00
Star Brilliant
76c40fb4dc Bump version to 1.3.5 2018-04-26 23:52:59 +08:00
Star Brilliant
174a465ac8 Limit the frequency of creating HTTP client 2018-04-26 23:52:35 +08:00
4 changed files with 20 additions and 11 deletions

View File

@@ -4,6 +4,10 @@ This Changelog records major changes between versions.
Not all changes are recorded. Please check git log for details. Not all changes are recorded. Please check git log for details.
## Version 1.3.5
- Limit the frequency of creating HTTP client on bad network condition
## Version 1.3.4 ## Version 1.3.4
- doh-client now silently fails in case of network error to prevent caching of SERVFAIL - doh-client now silently fails in case of network error to prevent caching of SERVFAIL

View File

@@ -40,15 +40,16 @@ import (
) )
type Client struct { type Client struct {
conf *config conf *config
bootstrap []string bootstrap []string
udpServers []*dns.Server udpServers []*dns.Server
tcpServers []*dns.Server tcpServers []*dns.Server
bootstrapResolver *net.Resolver bootstrapResolver *net.Resolver
cookieJar *cookiejar.Jar cookieJar *cookiejar.Jar
httpClientMux *sync.RWMutex httpClientMux *sync.RWMutex
httpTransport *http.Transport httpTransport *http.Transport
httpClient *http.Client httpClient *http.Client
httpClientLastCreate time.Time
} }
type DNSRequest struct { type DNSRequest struct {
@@ -124,6 +125,9 @@ func NewClient(conf *config) (c *Client, err error) {
func (c *Client) newHTTPClient() error { func (c *Client) newHTTPClient() error {
c.httpClientMux.Lock() c.httpClientMux.Lock()
defer c.httpClientMux.Unlock() defer c.httpClientMux.Unlock()
if !c.httpClientLastCreate.IsZero() && time.Now().Sub(c.httpClientLastCreate) < time.Duration(c.conf.Timeout)*time.Second {
return nil
}
if c.httpTransport != nil { if c.httpTransport != nil {
c.httpTransport.CloseIdleConnections() c.httpTransport.CloseIdleConnections()
} }
@@ -150,6 +154,7 @@ func (c *Client) newHTTPClient() error {
Transport: c.httpTransport, Transport: c.httpTransport,
Jar: c.cookieJar, Jar: c.cookieJar,
} }
c.httpClientLastCreate = time.Now()
return nil return nil
} }

View File

@@ -24,6 +24,6 @@
package main package main
const ( const (
VERSION = "1.3.4" VERSION = "1.3.5"
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)" USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
) )

View File

@@ -24,6 +24,6 @@
package main package main
const ( const (
VERSION = "1.3.4" VERSION = "1.3.5"
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)" USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
) )