mirror of
https://github.com/coredns/coredns.git
synced 2026-08-20 23:08:28 -04:00
plugin/cache: preserve monotonic time for TTL expiry (#8346)
Keep cache timestamps and TTL calculations on the time values returned by the cache clock. Converting them with UTC strips Go's monotonic clock reading and can extend cached entries when the wall clock moves backward. Add a regression test that verifies new cache items retain the original monotonic timestamp. Fixes #5478. Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
This commit is contained in:
4
plugin/cache/handler.go
vendored
4
plugin/cache/handler.go
vendored
@@ -26,7 +26,7 @@ func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||
return plugin.NextOrFailure(c.Name(), c.Next, ctx, w, rc)
|
||||
}
|
||||
|
||||
now := c.now().UTC()
|
||||
now := c.now()
|
||||
server := metrics.WithServer(ctx)
|
||||
|
||||
// On cache refresh, we will just use the DO bit from the incoming query for the refresh since we key our cache
|
||||
@@ -158,7 +158,7 @@ func (c *Cache) verifyWithTimeout(ctx context.Context, state request.Request, w
|
||||
// Should not happen: refreshed=true means the upstream response was cacheable.
|
||||
return true, res.code, res.err
|
||||
}
|
||||
now := c.now().UTC()
|
||||
now := c.now()
|
||||
if c.keepttl {
|
||||
now = fresh.stored
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user