mirror of
https://github.com/coredns/coredns.git
synced 2026-05-25 19:30:23 -04:00
fix(cache): prefer positive cache over SERVFAIL in ncache (#8003)
When serve_stale is enabled, a cached SERVFAIL in ncache shadows a valid positive entry in pcache because ncache is always checked first. SERVFAIL is transient and should not mask a known-good answer. When the ncache hit is a SERVFAIL, check pcache for a valid entry before returning the SERVFAIL. NXDOMAIN and NODATA are unaffected and still follow the existing ncache-first lookup per RFC 2308. Fixes #7956 Signed-off-by: umut-polat <52835619+umut-polat@users.noreply.github.com>
This commit is contained in:
11
plugin/cache/handler.go
vendored
11
plugin/cache/handler.go
vendored
@@ -192,6 +192,17 @@ func (c *Cache) getIfNotStale(now time.Time, state request.Request, server strin
|
||||
if i, ok := c.ncache.Get(k); ok {
|
||||
ttl := i.ttl(now)
|
||||
if i.matches(state) && (ttl > 0 || (c.staleUpTo > 0 && -ttl < int(c.staleUpTo.Seconds()))) {
|
||||
// SERVFAIL is transient; prefer a valid positive cache entry if one
|
||||
// exists, so a cached SERVFAIL does not shadow a previously good answer.
|
||||
if i.Rcode == dns.RcodeServerFailure {
|
||||
if p, pok := c.pcache.Get(k); pok {
|
||||
pttl := p.ttl(now)
|
||||
if p.matches(state) && (pttl > 0 || (c.staleUpTo > 0 && -pttl < int(c.staleUpTo.Seconds()))) {
|
||||
cacheHits.WithLabelValues(server, Success, c.zonesMetricLabel, c.viewMetricLabel).Inc()
|
||||
return p
|
||||
}
|
||||
}
|
||||
}
|
||||
cacheHits.WithLabelValues(server, Denial, c.zonesMetricLabel, c.viewMetricLabel).Inc()
|
||||
return i
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user