grafana/k6 · error
starting test
Error message
starting test: %w
What it means
After a successful upload, `k6 cloud` failed at client.StartTest — the request to actually launch the previously created load test (loadTest.GetId()) was rejected or failed in transport. The 'starting test' prefix identifies the stage; the wrapped ResponseError carries the decisive status code and API message.
Solutions
- Check the Grafana Cloud UI for a still-running instance of the test; stop it, then re-run
- If 401/403, refresh auth with `k6 cloud login` and retry
- If 429/402, reduce concurrent cloud runs or raise plan limits, then retry with backoff
- For 5xx/transport errors, retry after a short delay — the uploaded test remains usable, only the start needs repeating (re-invoking k6 cloud re-uploads)
Example fix
# before k6 cloud run script.js # 409: test already running # after k6 cloud stop --test <test-id> 2>/dev/null || true sleep 5 k6 cloud run script.js
Defensive patterns
Strategy: retry
Validate before calling
// ensure no active run before starting
run, _, _ := client.GetTestRun(ctx, loadTestID) // or ListTestRuns
if run != nil && isActive(run.Status) {
_ = client.StopTest(ctx, loadTestID)
time.Sleep(5 * time.Second)
} Try / catch
run, err := client.StartTest(ctx, loadTest.GetId())
if err != nil {
var re *cloudapiv6.ResponseError
if errors.As(err, &re) {
if re.Response.StatusCode == 409 { return fmt.Errorf("test already running; stop it first: %w", err) }
if re.Response.StatusCode == 429 || re.Response.StatusCode >= 500 { /* retry with backoff */ }
}
return fmt.Errorf("starting test: %w", err)
} Prevention
- Make CI pipelines idempotent: stop-or-ignore previous runs before starting
- Distinguish 409 (state) from 5xx (transient) in retry logic
- Keep a small delay between stop and start to let cloud state converge
When it happens
Trigger: 409 when a run of the same test is already active, 401/403 on expired or insufficient token permissions, 402/429 on plan or concurrency limits, or 5xx/transport failure contacting /cloud/v6 start endpoint.
Common situations: Re-running a test while a previous cloud run is still finishing (its teardown or abort grace period), quota exhaustion near the end of a billing period, or CI retries firing while the first run is starting.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- create or find load test
- invalid stack URL
- notify test run completed
- : .\n
- token is required to create cloud API client
AI-assisted analysis of grafana/k6@94169daab2 (2026-08-18).
Data as JSON: /api/errors/709cd9e27c92df97.
Report an issue: GitHub.
Appendix: source
Thrown at internal/cmd/cloud.go:303
if err != nil {
return err
}
executionPlan := test.derivedConfig.Scenarios.GetFullExecutionRequirements(et)
testURL, err := resolveCloudTestURL(cloudConfig.StackURL.String, loadTest.GetId())
if err != nil {
return err
}
printExecutionDescription(
gs, "cloud", test.sourceRootPath, testURL, test.derivedConfig, et, executionPlan, nil,
)
modifyAndPrintBar(gs, progressBar, pb.WithConstLeft("Run "), pb.WithConstProgress(1.0, "Archived"))
printCloudTestStatus(gs, "Archived")
return nil
}
run, err := client.StartTest(globalCtx, loadTest.GetId())
if err != nil {
return fmt.Errorf("starting test: %w", err)
}
testRunID := run.GetId()
// Trap Interrupts, SIGINTs and SIGTERMs.
gracefulStop := func(sig os.Signal) {
logger.WithField("sig", sig).Print("Stopping cloud test run in response to signal...")
// Do this in a separate goroutine so that if it blocks, the
// second signal can still abort the process execution.
go func() {
stopErr := client.StopTest(context.WithoutCancel(globalCtx), testRunID)
if stopErr != nil {
logger.WithError(stopErr).Error("Stop cloud test error")
} else {
logger.Info("Successfully sent signal to stop the cloud test, now waiting for it to actually stop...")
}
globalCancel()
}()
}View on GitHub (pinned to 94169daab2)