mirror of
https://github.com/coredns/coredns.git
synced 2025-08-06 22:37:03 +02:00
fix: handle cached connection closure in forward plugin (#7427)
This commit is contained in:
parent
2c2b075eaa
commit
6ba43927b6
@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/coredns/coredns/plugin/dnstap"
|
"github.com/coredns/coredns/plugin/dnstap"
|
||||||
"github.com/coredns/coredns/plugin/metadata"
|
"github.com/coredns/coredns/plugin/metadata"
|
||||||
clog "github.com/coredns/coredns/plugin/pkg/log"
|
clog "github.com/coredns/coredns/plugin/pkg/log"
|
||||||
"github.com/coredns/coredns/plugin/pkg/proxy"
|
proxyPkg "github.com/coredns/coredns/plugin/pkg/proxy"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
@ -36,7 +36,7 @@ const (
|
|||||||
type Forward struct {
|
type Forward struct {
|
||||||
concurrent int64 // atomic counters need to be first in struct for proper alignment
|
concurrent int64 // atomic counters need to be first in struct for proper alignment
|
||||||
|
|
||||||
proxies []*proxy.Proxy
|
proxies []*proxyPkg.Proxy
|
||||||
p Policy
|
p Policy
|
||||||
hcInterval time.Duration
|
hcInterval time.Duration
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ type Forward struct {
|
|||||||
maxConcurrent int64
|
maxConcurrent int64
|
||||||
failfastUnhealthyUpstreams bool
|
failfastUnhealthyUpstreams bool
|
||||||
|
|
||||||
opts proxy.Options // also here for testing
|
opts proxyPkg.Options // also here for testing
|
||||||
|
|
||||||
// ErrLimitExceeded indicates that a query was rejected because the number of concurrent queries has exceeded
|
// ErrLimitExceeded indicates that a query was rejected because the number of concurrent queries has exceeded
|
||||||
// the maximum allowed (maxConcurrent)
|
// the maximum allowed (maxConcurrent)
|
||||||
@ -65,18 +65,18 @@ type Forward struct {
|
|||||||
|
|
||||||
// New returns a new Forward.
|
// New returns a new Forward.
|
||||||
func New() *Forward {
|
func New() *Forward {
|
||||||
f := &Forward{maxfails: 2, tlsConfig: new(tls.Config), expire: defaultExpire, p: new(random), from: ".", hcInterval: hcInterval, opts: proxy.Options{ForceTCP: false, PreferUDP: false, HCRecursionDesired: true, HCDomain: "."}}
|
f := &Forward{maxfails: 2, tlsConfig: new(tls.Config), expire: defaultExpire, p: new(random), from: ".", hcInterval: hcInterval, opts: proxyPkg.Options{ForceTCP: false, PreferUDP: false, HCRecursionDesired: true, HCDomain: "."}}
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetProxy appends p to the proxy list and starts healthchecking.
|
// SetProxy appends p to the proxy list and starts healthchecking.
|
||||||
func (f *Forward) SetProxy(p *proxy.Proxy) {
|
func (f *Forward) SetProxy(p *proxyPkg.Proxy) {
|
||||||
f.proxies = append(f.proxies, p)
|
f.proxies = append(f.proxies, p)
|
||||||
p.Start(f.hcInterval)
|
p.Start(f.hcInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetProxyOptions setup proxy options
|
// SetProxyOptions setup proxy options
|
||||||
func (f *Forward) SetProxyOptions(opts proxy.Options) {
|
func (f *Forward) SetProxyOptions(opts proxyPkg.Options) {
|
||||||
f.opts = opts
|
f.opts = opts
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
|||||||
for {
|
for {
|
||||||
ret, err = proxy.Connect(ctx, state, opts)
|
ret, err = proxy.Connect(ctx, state, opts)
|
||||||
|
|
||||||
if err == ErrCachedClosed { // Remote side closed conn, can only happen with TCP.
|
if err == proxyPkg.ErrCachedClosed { // Remote side closed conn, can only happen with TCP.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Retry with TCP if truncated and prefer_udp configured.
|
// Retry with TCP if truncated and prefer_udp configured.
|
||||||
@ -254,7 +254,7 @@ func (f *Forward) ForceTCP() bool { return f.opts.ForceTCP }
|
|||||||
func (f *Forward) PreferUDP() bool { return f.opts.PreferUDP }
|
func (f *Forward) PreferUDP() bool { return f.opts.PreferUDP }
|
||||||
|
|
||||||
// List returns a set of proxies to be used for this client depending on the policy in f.
|
// List returns a set of proxies to be used for this client depending on the policy in f.
|
||||||
func (f *Forward) List() []*proxy.Proxy { return f.p.List(f.proxies) }
|
func (f *Forward) List() []*proxyPkg.Proxy { return f.p.List(f.proxies) }
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrNoHealthy means no healthy proxies left.
|
// ErrNoHealthy means no healthy proxies left.
|
||||||
|
Loading…
Reference in New Issue
Block a user