fix(cache): prefer positive cache over SERVFAIL in ncache#8003
Merged
Conversation
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 coredns#7956 Signed-off-by: umut-polat <52835619+umut-polat@users.noreply.github.com>
cf8cac1 to
db53a3d
Compare
yongtang
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
serve_staleis enabled, a cached SERVFAIL inncacheshadows a valid positive entry inpcachebecausencacheis always checked first ingetIfNotStale. SERVFAIL is transient (e.g. upstream hiccup) and should not mask a known-good answer that is still servable.What changed
plugin/cache/handler.go: when thencachehit is a SERVFAIL, checkpcachefor a valid entry before returning. If a positive entry exists and is servable (fresh or within the stale window), return it instead.plugin/cache/cache_test.go: addTestServfailDoesNotShadowPositiveCachethat injects both a SERVFAIL inncacheand a positive entry inpcache, then verifies the lookup returns the positive entry.NXDOMAIN and NODATA follow the existing ncache-first order per RFC 2308 and are unaffected.
Repro (before fix)
With
serve_staleenabled:pcachencacheFixes #7956