grafana/k6 · error

setInterval requires a >0 timeout parameter, received %.2f

Error message

setInterval requires a >0 timeout parameter, received %.2f

What it means

Returned by ws.Socket.SetInterval when the interval parameter, converted from milliseconds to a time.Duration, is <= 0. Identical guard to setTimeout: a non-positive interval would make the underlying time.Ticker panic or never fire, so it is rejected up front with the offending value shown to two decimals.

Source

Thrown at internal/js/modules/k6/ws/ws.go:454

		case <-s.done:
			return
		}
	}()

	return nil
}

// SetInterval executes the provided function inside the socket's event loop each interval time, which is
// in ms
func (s *Socket) SetInterval(fn sobek.Callable, intervalMs float64) error {
	// Starts a goroutine, blocks forever on the ticker 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 SetInterval() JS API.
	d := time.Duration(intervalMs * float64(time.Millisecond))
	if d <= 0 {
		return fmt.Errorf("setInterval requires a >0 timeout parameter, received %.2f", intervalMs)
	}
	go func() {
		ticker := time.NewTicker(d)
		defer ticker.Stop()

		for {
			select {
			case <-ticker.C:
				select {
				case s.scheduled <- fn:
				case <-s.done:
					return
				}

			case <-s.done:
				return
			}
		}

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Pass a positive millisecond value: socket.setInterval(fn, 500)
  2. For a single delayed call use socket.setTimeout instead
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/modules/k6/ws/ws.go:454 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


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