grafana/k6 · error
setTimeout requires a >0 timeout parameter, received %.2f
Error message
setTimeout requires a >0 timeout parameter, received %.2f
What it means
Returned by ws.Socket.SetTimeout when the timeout parameter, converted from milliseconds, is <= 0 (the guard rejects d <= 0 after duration conversion). The value is reported with two decimals so fractional or negative inputs are visible. The callback is never scheduled and the socket's timer machinery is untouched.
Solutions
- Pass a positive millisecond value: socket.setTimeout(fn, 1000)
- Guard dynamic values: socket.setTimeout(fn, Math.max(1, delay))
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/ws/ws.go:425 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/7fc604dac5b549ae.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/ws/ws.go:425
Tags: s.tagsAndMeta.Tags,
},
Time: pongTimestamp,
Metadata: s.tagsAndMeta.Metadata,
Value: metrics.D(pongTimestamp.Sub(pingTimestamp)),
})
}
// SetTimeout executes the provided function inside the socket's event loop after at least the provided
// timeout, which is in ms, has elapsed
func (s *Socket) SetTimeout(fn sobek.Callable, timeoutMs float64) error {
// Starts a goroutine, blocks once on the timeout and pushes the callable
// back to the main loop through the scheduled channel.
//
// Intentionally not using the generic GetDurationValue() helper, since this
// API is meant to use ms, similar to the original SetTimeout() JS API.
d := time.Duration(timeoutMs * float64(time.Millisecond))
if d <= 0 {
return fmt.Errorf("setTimeout requires a >0 timeout parameter, received %.2f", timeoutMs)
}
go func() {
select {
case <-time.After(d):
select {
case s.scheduled <- fn:
case <-s.done:
return
}
case <-s.done:
return
}
}()
return nil
}
View on GitHub (pinned to 01ffac6f24)