grafana/k6 · error

invalid DNS TTL: %s

Error message

invalid DNS TTL: %s

What it means

The ttl value of the host resolver options (K6_DNS_TTL or dns.ttl option) is neither 'inf', '0', empty, nor a parseable positive duration. ParseExtendedDuration handles extended formats like '1h30m' and k8s-style '300ms'; a negative, malformed, or non-numeric string falls through to this error when the resolver is configured at startup.

Source

Thrown at internal/js/runner.go:623

	return nil
}

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 = types.DefaultDNSConfig().TTL.String
		fallthrough
	default:
		var err error
		ttl, err = types.ParseExtendedDuration(ttlS)
		if ttl < 0 || err != nil {
			return ttl, fmt.Errorf("invalid DNS TTL: %s", ttlS)
		}
	}
	return ttl, nil
}

// Runs an exported function in its own temporary VU, optionally with an argument. Execution is
// interrupted if the context expires. No error is returned if the part does not exist.
func (r *Runner) runPart(
	parentCtx context.Context,
	out chan<- metrics.SampleContainer,
	name string,
	arg any,
) (sobek.Value, error) {
	ctx, cancel := context.WithCancel(parentCtx)
	defer cancel()

	vu, err := r.newVU(ctx, 0, 0, out)
	if err != nil {

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Use a valid duration string such as '1m', '30s', '500ms', or the special values '0' (no caching) and 'inf' (cache for a year)
  2. Check for typos and stray units in the K6_DNS_TTL environment variable and the dns.ttl option
  3. Avoid negative values; TTL must be zero or positive
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/runner.go:623 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/b1d7de4f29738f79. Report an issue: GitHub.