mirror of
https://github.com/coredns/coredns.git
synced 2026-07-17 05:00:12 -04:00
plugin/forward: Fix incorrect failover counter reset (#8277)
* plugin/forward: Fix incorrect failover counter reset This PR fixes the isseue where resetting the failover counter caused retry the same upstreams until timeout instead of stopping after one pass. Signed-off-by: Yong Tang <yong.tang.github@outlook.com> * golint fix Signed-off-by: Yong Tang <yong.tang.github@outlook.com> --------- Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"slices"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
@@ -126,6 +127,7 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
||||
}
|
||||
|
||||
fails := 0
|
||||
failoverAttempts := 0
|
||||
var span, child ot.Span
|
||||
var upstreamErr error
|
||||
span = ot.SpanFromContext(ctx)
|
||||
@@ -236,16 +238,11 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
||||
|
||||
// Check if we have a failover Rcode defined, check if we match on the code
|
||||
tryNext := false
|
||||
for _, failoverRcode := range f.failoverRcodes {
|
||||
// if we match, we continue to the next upstream in the list
|
||||
if failoverRcode == ret.Rcode {
|
||||
if fails < len(f.proxies) {
|
||||
tryNext = true
|
||||
}
|
||||
}
|
||||
if slices.Contains(f.failoverRcodes, ret.Rcode) {
|
||||
failoverAttempts++
|
||||
tryNext = failoverAttempts < len(f.proxies)
|
||||
}
|
||||
if tryNext {
|
||||
fails++
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user