grafana/k6 · error
invalid DNS TTL: %s
Error message
invalid DNS TTL: %s
What it means
Root error from parseTTL: the ttl string failed ParseExtendedDuration or parsed to a negative duration. Valid inputs are exactly '0' (cache disabled), 'inf' (cached ~1 year), '' (falls back to k6's default '1m'), or a single non-negative duration like '300s'/'5m'/'1h'. Comma-separated TTL lists are NOT supported in the browser module even though k6's HTTP stack accepts them.
Source
Thrown at internal/js/modules/k6/browser/common/network_manager.go:201
// Parse a string representation of TTL to time.Duration.
// Copied from https://github.com/grafana/k6/blob/fb70bc6f3d3f22a40e65f32deea3cea1b6d70a76/js/runner.go#L479
func parseTTL(ttlS string) (time.Duration, error) {
ttl := time.Duration(0)
switch ttlS {
case "inf":
// cache "infinitely"
ttl = time.Hour * 24 * 365
case "0":
// disable cache
case "":
ttlS = k6types.DefaultDNSConfig().TTL.String
fallthrough
default:
var err error
ttl, err = k6types.ParseExtendedDuration(ttlS)
if ttl < 0 || err != nil {
return ttl, fmt.Errorf("invalid DNS TTL: %s", ttlS)
}
}
return ttl, nil
}
func (m *NetworkManager) deleteRequestByID(reqID network.RequestID) {
m.reqsMu.Lock()
defer m.reqsMu.Unlock()
delete(m.reqIDToRequest, reqID)
}
func (m *NetworkManager) emitRequestMetrics(req *Request) {
state := m.vu.State()
tags := state.Tags.GetCurrentValues().Tags
if state.Options.SystemTags.Has(k6metrics.TagMethod) {
tags = tags.With("method", req.method)
}View on GitHub (pinned to 93accf6570)
Solutions
- Use a single valid duration: '1m', '300s', '1h', or '0'/'inf'
- Never pass a comma list to dns.ttl in scripts that use the browser module
- Sanity-check generated/templated options before running
- If you need per-lookup TTL variety, keep it in HTTP-only scenarios and override dns.ttl for browser scenarios
Example fix
// before
export const options = { dns: { ttl: '60s,10m' } };
// after
export const options = { dns: { ttl: '60s' } }; Defensive patterns
Strategy: validation
Validate before calling
const ttl = '60s';
if (!/^(0|inf|\d+(\.\d+)?(ms|s|m|h))$/.test(ttl)) {
throw new Error(`dns.ttl '${ttl}' invalid; use 0, inf, or a single duration`);
} Type guard
function isValidTtlString(s) {
if (s === '' || s === '0' || s === 'inf') return true;
return /^\d+(\.\d+)?(ms|s|m|h)$/.test(s); // no commas, no negatives
} Prevention
- Memorize the valid set: '', '0', 'inf', single duration
- Comma lists are HTTP-module-only; never in browser scenarios
- Beware unit typos: '1hr' invalid, '1h' valid
When it happens
Trigger: dns.ttl set to 'abc', '1hr', '-1m', or '60s,5m'. Empty string is fine (default applied); '0' and 'inf' are special-cased; everything else must parse as one non-negative duration.
Common situations: Sharing one options object between HTTP and browser scenarios where the HTTP side uses a TTL list; hand-edited durations with wrong units; negative values from templating bugs.
Related errors
- newResolver(%+v): %w
- parsing TTL: %w
- predicate function is not callable
- "handler" argument cannot be nil
- clip area is either empty or outside the viewport
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/85c59961a9015282.
Report an issue: GitHub.