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
- Use a string like '10s' or a millisecond number like 10000
- For env config, parse explicitly: parseInt(__ENV.TIMEOUT_MS, 10)
- 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
- Prefer '10s'-style strings over bare numbers to avoid ms/s ambiguity
- Parse env-provided durations once in init instead of passing raw strings
- Unit-test shared param helpers with both accepted forms
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
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- failed to dial: %w
- %s should be a time duration value: %w
- invalid GRPC Stream's parameters: %w
- invalid metadata param: %w
- unknown param: %q
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/a645047edfde4e33.
Report an issue: GitHub.