grafana/k6 · critical

error while initializing executor %s: %w

Error message

error while initializing executor %s: %w

What it means

The Scheduler is k6's top-level execution coordinator. After VU initialization it calls Init(ctx) on every configured executor (scenario); if any one fails, initialization aborts and this error wraps the scenario name plus the underlying cause. In practice Init fails inside lib/executor when an arrival-rate executor rebuilds its execution tuple from MaxVUs (GetNewExecutionTupleFromValue) and the execution segment/sequence setup is inconsistent. The error is fatal: the test never starts.

Source

Thrown at internal/execution/scheduler.go:317

		initErr = err
		cancel(initErr)
	}

	if initErr != nil {
		return initErr
	}

	e.state.SetInitVUFunc(func(ctx context.Context, logger *logrus.Entry) (lib.InitializedVU, error) {
		return e.initVU(ctx, samplesOut, logger)
	})

	e.state.SetExecutionStatus(lib.ExecutionStatusInitExecutors)
	logger.Debugf("Finished initializing needed VUs, start initializing executors...")
	for _, exec := range e.executors {
		executorConfig := exec.GetConfig()

		if err := exec.Init(ctx); err != nil {
			return fmt.Errorf("error while initializing executor %s: %w", executorConfig.GetName(), err)
		}
		logger.Debugf("Initialized executor %s", executorConfig.GetName())
	}

	e.state.SetExecutionStatus(lib.ExecutionStatusInitDone)
	logger.Debugf("Initialization completed")
	return nil
}

// runExecutor gets called by the public Run() method once per configured
// executor, each time in a new goroutine. It is responsible for waiting out the
// configured startTime for the specific executor and then running its Run()
// method.
func (e *Scheduler) runExecutor(
	runCtx context.Context, runResults chan<- error, engineOut chan<- metrics.SampleContainer, executor lib.Executor,
) {
	executorConfig := executor.GetConfig()
	executorStartTime := executorConfig.GetStartTime()

View on GitHub (pinned to 93accf6570)

Solutions

  1. Read the text after the colon - the wrapped cause names the exact failure, and the scenario name before it identifies the offending entry in options.scenarios
  2. Validate locally without running load: `k6 inspect --execution-requirements script.js` parses options and shows the planned executors
  3. If using --execution-segment / --execution-segment-sequence, verify the sequence partitions [0,1] and every segment fits it (0<=start<end<=1, segments tiled onto the sequence)
  4. Bisect: temporarily reduce scenarios to a single executor and re-add the others until the failing one is isolated

Example fix

# before: segment not representable in the given sequence
k6 run --execution-segment '3/8:5/8' --execution-segment-sequence '0,1/8,3/8,7/8' script.js
# segment [3/8,5/8) cannot be expressed by that sequence -> executor Init fails

# after: sequence that contains both cut points 3/8 and 5/8
k6 run --execution-segment '3/8:5/8' --execution-sequence '0,3/8,5/8,1' script.js 2>/dev/null || \
k6 run --execution-segment '3/8:5/8' --execution-segment-sequence '0,3/8,5/8,1' script.js
Defensive patterns

Strategy: validation

Validate before calling

# CI pre-flight: parses scenarios and computes executor requirements without running load
k6 inspect --execution-requirements script.js > /dev/null || exit 1

# sanity-check segment flags before distributing a run
k6 inspect --execution-requirements \
  --execution-segment '3/8:5/8' \
  --execution-segment-sequence '0,3/8,5/8,1' script.js > /dev/null || exit 1

Prevention

When it happens

Trigger: k6 run with --execution-segment / --execution-segment-sequence flags that conflict (a segment the sequence cannot produce, or a segment sequence that does not partition 0..1); a scenario whose MaxVUs cannot be mapped by the configured segment; any extension executor whose Init returns an error. The %s is the key from options.scenarios.<name>.

Common situations: Distributed k6 runs using execution segment flags to shard load across instances; hand-edited scenario blocks in archives (k6 run archive.tar); CI pipelines that assemble options from environment variables or flags without local validation.

Related errors


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