diff --git a/upstream/dns_upstream.go b/upstream/dns_upstream.go index 89584e11..2902ca2e 100644 --- a/upstream/dns_upstream.go +++ b/upstream/dns_upstream.go @@ -27,7 +27,7 @@ func NewDnsUpstream(endpoint string, proto string, tlsServerName string) (Upstre var tlsConfig *tls.Config - if tlsServerName != "" { + if proto == "tcp-tls" { tlsConfig = new(tls.Config) tlsConfig.ServerName = tlsServerName } @@ -101,6 +101,9 @@ func (u *DnsUpstream) exchange(proto string, query *dns.Msg) (r *dns.Msg, err er conn.Close() // Not giving it back } - u.transport.Yield(conn) + if err == nil { + // Return it back to the connections cache if there were no errors + u.transport.Yield(conn) + } return r, err } diff --git a/upstream/helpers.go b/upstream/helpers.go index 1313b8e0..209da533 100644 --- a/upstream/helpers.go +++ b/upstream/helpers.go @@ -72,8 +72,7 @@ func CreateResolver(bootstrap string) *net.Resolver { PreferGo: true, Dial: func(ctx context.Context, network, address string) (net.Conn, error) { var d net.Dialer - conn, err := d.DialContext(ctx, network, bootstrap) - return conn, err + return d.DialContext(ctx, network, bootstrap) }, } } diff --git a/upstream/upstream.go b/upstream/upstream.go index c2ab1826..faef224e 100644 --- a/upstream/upstream.go +++ b/upstream/upstream.go @@ -52,4 +52,6 @@ func (p *UpstreamPlugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r * } // Name implements interface for CoreDNS plugin -func (p *UpstreamPlugin) Name() string { return "upstream" } +func (p *UpstreamPlugin) Name() string { + return "upstream" +}