coredns/coredns · error
cache min TTL can not be negative: %d
Error message
cache min TTL can not be negative: %d
What it means
When the cache plugin's directive specifies a minimum positive-response TTL (`cache <zones> <pttl> <minpttl>`), the min TTL must not be negative. Unlike the main TTL, zero IS allowed for the min TTL (meaning no floor); only negative values trigger this error in cacheParse.
Source
Thrown at plugin/cache/setup.go:100
ca.pcap = pcap
if len(args) > 1 {
pttl, err := strconv.Atoi(args[1])
if err != nil {
return nil, err
}
// Reserve 0 (and smaller for future things)
if pttl <= 0 {
return nil, fmt.Errorf("cache TTL can not be zero or negative: %d", pttl)
}
ca.pttl = time.Duration(pttl) * time.Second
if len(args) > 2 {
minpttl, err := strconv.Atoi(args[2])
if err != nil {
return nil, err
}
// Reserve < 0
if minpttl < 0 {
return nil, fmt.Errorf("cache min TTL can not be negative: %d", minpttl)
}
ca.minpttl = time.Duration(minpttl) * time.Second
}
}
case Denial:
args := c.RemainingArgs()
if len(args) == 0 {
return nil, c.ArgErr()
}
ncap, err := strconv.Atoi(args[0])
if err != nil {
return nil, err
}
ca.ncap = ncap
if len(args) > 1 {
nttl, err := strconv.Atoi(args[1])
if err != nil {
return nil, errView on GitHub (pinned to 558c9757a9)
Solutions
- Change the min positive TTL to 0 or a positive integer, e.g. `cache example.org 30 5`.
- Drop the third argument if no floor is needed; the min TTL then defaults to 0.
- Check whether minpttl <= pttl constraints make sense for your intent (min TTL should typically be <= the max TTL).
Example fix
// before (Corefile) cache example.org 30 -5 // after cache example.org 30 5
Defensive patterns
Strategy: validation
Validate before calling
const minPttl = 5; if (!Number.isInteger(minPttl) || minPttl < 0) { throw new Error(`cache min success TTL must be >= 0, got ${minPttl}`); } Prevention
- Remember min TTL of 0 is allowed; only negatives are invalid.
- Keep min TTL <= max TTL for coherent behavior.
- Watch for stray '-' characters in generated configs.
When it happens
Trigger: Corefile like `cache example.org 30 -5` where args[2] of the success clause parses to a negative integer and is assigned to ca.minpttl.
Common situations: Sign typos in generated configs, misplacing a hyphen from another directive, or misunderstanding that min TTL floor must be 0 or positive.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- cache TTL can not be zero or negative: %d
- invalid negative response TTL for serve_stale
- serve_stale response TTL must be a whole number of seconds
- serve_stale response TTL exceeds the DNS TTL range
- prefetch amount should be positive: %d
AI-assisted analysis of coredns/coredns@558c9757a9 (2026-09-06).
Data as JSON: /api/errors/f0e731bcbe056f3b.
Report an issue: GitHub.