fix: No failover to next upstream when receiving SERVFAIL or REFUSED response codes(#7457) (#7458)

This commit is contained in:
Fitz_dev
2025-09-13 05:45:01 +08:00
committed by GitHub
parent 155f451957
commit 9683de0feb
5 changed files with 166 additions and 0 deletions

View File

@@ -51,6 +51,7 @@ type Forward struct {
expire time.Duration
maxConcurrent int64
failfastUnhealthyUpstreams bool
failoverRcodes []int
opts proxyPkg.Options // also here for testing
@@ -206,6 +207,21 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
return 0, nil
}
// 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 tryNext {
fails++
continue
}
// Check if we have an alternate Rcode defined, check if we match on the code
for _, alternateRcode := range f.nextAlternateRcodes {
if alternateRcode == ret.Rcode && f.Next != nil { // In case we do not have a Next handler, just continue normally