grafana/k6 · error

invalid timeout value: %w

Error message

invalid timeout value: %w

What it means

The timeout key in call params (client.invoke() / new grpc.Stream()) is converted with types.GetDurationValue (lib/types/types.go:197): numbers are treated as milliseconds, strings must be valid duration literals such as '500ms' or '2s', and every other JS type (object, boolean, array) or malformed string errors out as 'invalid timeout value'.

Source

Thrown at internal/js/modules/k6/grpc/params.go:60

	for _, k := range params.Keys() {
		switch k {
		case "metadata":
			md, err := newMetadata(params.Get(k))
			if err != nil {
				return result, fmt.Errorf("invalid metadata param: %w", err)
			}

			result.Metadata = md
		case "tags":
			if err := common.ApplyCustomUserTags(rt, &result.TagsAndMeta, params.Get(k)); err != nil {
				return result, fmt.Errorf("metric tags: %w", err)
			}
		case "timeout":
			var err error
			v := params.Get(k).Export()
			result.Timeout, err = types.GetDurationValue(v)
			if err != nil {
				return result, fmt.Errorf("invalid timeout value: %w", err)
			}
		case "discardResponseMessage":
			result.DiscardResponseMessage = params.Get(k).ToBoolean()
		default:
			return result, fmt.Errorf("unknown param: %q", k)
		}
	}

	return result, nil
}

// newMetadata constructs a metadata.MD from the input value.
func newMetadata(input sobek.Value) (metadata.MD, error) {
	md := metadata.New(nil)

	if common.IsNullish(input) {
		return md, nil
	}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Use a string like '10s' or a millisecond number like 10000
  2. For env config, parse explicitly: parseInt(__ENV.TIMEOUT_MS, 10)
  3. If config stores seconds, multiply by 1000 before passing

Example fix

// before
client.invoke(method, req, { timeout: '10 sec' });

// after
client.invoke(method, req, { timeout: '10s' });
Defensive patterns

Strategy: validation

Validate before calling

const DURATION_RE = /^\d+(\.\d+)?(ns|us|ms|s|m|h)$/;
function isDurationValue(v) {
  return typeof v === 'number' || (typeof v === 'string' && DURATION_RE.test(v));
}
if (params.timeout != null && !isDurationValue(params.timeout)) {
  throw new Error(`invalid timeout: ${params.timeout} (use '10s' or milliseconds)`);
}
client.invoke(method, req, params);

Type guard

function isDurationValue(v) {
  return typeof v === 'number' || (typeof v === 'string' && /^\d+(\.\d+)?(ns|us|ms|s|m|h)$/.test(v));
}

Prevention

When it happens

Trigger: { timeout: true }; { timeout: {} }; { timeout: 'fast' }; { timeout: '1sec' } (unknown unit); { timeout: '10 seconds' } (spaces not allowed).

Common situations: Env-provided timeouts with human-readable units; config values expressed in seconds passed as bare numbers and silently interpreted as milliseconds; copy-paste of HTTP timeout formats.

Understand the failure class

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/a645047edfde4e33. Report an issue: GitHub.