Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix socket leak #8

Merged
merged 1 commit into from
Apr 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions provider_google.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"net/http"
"net/url"
"time"
)

const (
Expand Down Expand Up @@ -127,6 +128,23 @@ func NewGDNSProvider(endpoint string, opts *GDNSOptions) (*GDNSProvider, error)
g.dns = d
}

// custom transport for supporting servernames which may not match the url,
// in cases where we request directly against an IP
tr := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
TLSClientConfig: &tls.Config{ServerName: g.url.Host},
}
g.client = &http.Client{Transport: tr}

return g, nil
}

Expand All @@ -138,6 +156,7 @@ type GDNSProvider struct {
host string
opts *GDNSOptions
dns *SimpleDNSClient
client *http.Client
}

func (g GDNSProvider) newRequest(q DNSQuestion) (*http.Request, error) {
Expand Down Expand Up @@ -206,14 +225,7 @@ func (g GDNSProvider) Query(q DNSQuestion) (*DNSResponse, error) {
return nil, err
}

// custom transport for supporting servernames which may not match the url,
// in cases where we request directly against an IP
tr := &http.Transport{
TLSClientConfig: &tls.Config{ServerName: g.url.Host},
}
client := &http.Client{Transport: tr}

httpresp, err := client.Do(httpreq)
httpresp, err := g.client.Do(httpreq)
if err != nil {
return nil, err
}
Expand Down