plugin/cache: `FAILURE_RECHECK` makes `serve_stale ... verify` return stale answers without verifying
What happened:
In the cache plugin, serve_stale in verify refresh mode takes the form serve_stale [DURATION] verify [VERIFY_TIMEOUT [RESPONSE_TTL [FAILURE_RECHECK]]]. A non-zero FAILURE_RECHECK does two things:
- It limits how often a failed refresh is retried. This is what the name says.
- While a refresh is already running for a stale cache entry, every other request for that entry returns the stale answer right away instead of starting its own refresh, even when the running refresh succeeds and the upstream is healthy.
Both behaviors are documented, but the second one conflicts with what verify mode is meant to do.
What you expected to happen:
We expected FAILURE_RECHECK to only limit retries after a failed refresh, which is what its name and its first documented sentence say. When no refresh has failed, we expected verify to do what it promises: check with the upstream before returning a stale answer.
These two sentences in plugin/cache/README.md say different things (emphasis mine):
On REFRESH_MODE:
Setting this value to
verifycan lead to increased latency when serving stale responses, but will prevent stale entries from ever being served if an updated response can be retrieved from the source.
On FAILURE_RECHECK:
While a refresh is in flight or its failure recheck period is active, the stale entry is served immediately without another upstream request.
A refresh that is already running and about to succeed is exactly a case where "an updated response can be retrieved from the source".
How to reproduce it (as minimally and precisely as possible):
- Use the Corefile below, with a healthy upstream.
- Let a cache entry expire, so the next query takes the stale path.
- Send several queries for that name at the same time.
- Only one of them starts the verify. The others return the stale entry, and
coredns_cache_served_stale_totalincreases, even though the upstream answers normally and the refresh succeeds. - Remove
FAILURE_RECHECK(serve_stale 336h verify 500ms) and repeat. Every request now waits for its own verify, and the counter stays at 0.
Anything else we need to know?:
We use verify so that a client does not get an old IP address after a service has moved. The two behaviors cannot be enabled separately, and we found no setting that keeps the retry limit without the second one, so we had to drop FAILURE_RECHECK entirely and go back to serve_stale 336h verify 500ms.
Our suggestion is to separate the two behaviors.
- In
verifymode, make the other requests wait for the refresh that is already running instead of returning the stale answer, bounded byVERIFY_TIMEOUTwhen it is set. Still one upstream query per entry, and the promise holds. - Or apply only the delay after a failed refresh, and let every request run its own verify even while one is already running. The promise holds, at the cost of one upstream query per concurrent request.
- Or move the second behavior to its own option, so that
FAILURE_RECHECKonly does what its name says. - If the behavior stays as it is, please say so in the
REFRESH_MODEparagraph too. Right now the two paragraphs say different things.
FAILURE_RECHECK was added in #8411.
Environment:
- the version of CoreDNS: 1.14.7
- Corefile:
cache {
success 65536 20 15
serve_stale 336h verify 500ms 0 10s
}
forward . /etc/resolv.conf {
prefer_udp
}- logs, if applicable: nothing is logged for this. It is only visible in
coredns_cache_served_stale_total. - OS (e.g:
cat /etc/os-release): Amazon Linux 2023, amd64, official CoreDNS container image - Others: Kubernetes 1.36, as the cluster DNS
Source: coredns/coredns