{"record":{"id":"0919c4057fe57a3c","repo":"grafana/k6","slug":"max-vus-w","errorCode":null,"errorMessage":"max_vus: %w","messagePattern":"max_vus: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloudapi/provisioning/api.go","lineNumber":206,"sourceCode":"// safe retries. The caller provides options as pre-marshalled JSON.\nfunc (c *Client) StartLocalExecution(\n\tctx context.Context, loadTestID int64, req StartLocalExecutionRequest,\n) (*StartLocalExecutionResponse, error) {\n\t// Generate idempotency key: 8 random bytes hex-encoded (16 chars).\n\tvar key [8]byte\n\tif _, err := rand.Read(key[:]); err != nil {\n\t\treturn nil, fmt.Errorf(\"generating idempotency key: %w\", err)\n\t}\n\n\t// SDK adapter: unmarshal json.RawMessage → map[string]any.\n\tvar opts map[string]any\n\tif err := json.Unmarshal(req.Options, &opts); err != nil {\n\t\treturn nil, fmt.Errorf(\"unmarshalling options for SDK: %w\", err)\n\t}\n\n\tmaxVUs, err := toInt32(req.MaxVUs)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"max_vus: %w\", err)\n\t}\n\ttotalDuration, err := toInt32(req.TotalDuration)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"total_duration: %w\", err)\n\t}\n\n\tsdkReq := k6cloud.NewStartLocalExecutionTestRequest(opts, maxVUs, totalDuration)\n\n\tif req.ArchiveSize > 0 {\n\t\tv, err := toInt32(req.ArchiveSize)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"archive_size: %w\", err)\n\t\t}\n\t\tsdkReq.SetArchiveSize(v)\n\t} else {\n\t\tsdkReq.SetArchiveSizeNil()\n\t}\n","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/cloudapi/provisioning/api.go#L188-L224","documentation":"Returned by Client.StartLocalExecution (internal/cloudapi/provisioning/api.go:206) when req.MaxVUs (int64) does not fit in int32, because the underlying cloud SDK models max_vus as int32 (toInt32 at api.go:296-301 rejects anything outside [-2147483648, 2147483647]). A VU count above 2,147,483,647 is far beyond any executable load, so in practice this signals garbage input (overflow/negative sentinel) rather than an ambitious test.","triggerScenarios":"StartLocalExecutionRequest.MaxVUs > math.MaxInt32 (or < math.MinInt32): usually an uninitialized/negative value used as a sentinel, or a computed sum over overflowing from a misconfigured options structure.","commonSituations":"Callers deriving MaxVUs via arithmetic on untrusted config; using -1 as 'unknown' marker and forgetting to replace it; tests with absurd fixture numbers.","solutions":["Check how the caller computes MaxVUs (usually lib.Options.Scenarios VU totals in cmd) and clamp or fail earlier on unreasonable values.","Replace int sentinel values like -1 with a real count before constructing the request.","Validate 0 < MaxVUs <= 2_000_000 (k6 Cloud's practical ceiling) before calling StartLocalExecution."],"exampleFix":"// before\nresp, err := c.StartLocalExecution(ctx, id, provisioning.StartLocalExecutionRequest{MaxVUs: computedMaxVUs})\n\n// after\nif req.MaxVUs <= 0 || req.MaxVUs > 2_000_000 {\n\treturn fmt.Errorf(\"max_vus %d out of supported range (1..2000000)\", req.MaxVUs)\n}\nresp, err := c.StartLocalExecution(ctx, id, provisioning.StartLocalExecutionRequest{MaxVUs: computedMaxVUs})","handlingStrategy":"validation","validationCode":"const maxCloudVUs = int64(2_000_000) // practical k6 Cloud ceiling, far under int32\n\nfunc validMaxVUs(v int64) bool {\n\treturn v > 0 && v <= maxCloudVUs\n}\n\nif !validMaxVUs(req.MaxVUs) {\n\treturn fmt.Errorf(\"max_vus %d outside supported range 1..%d\", req.MaxVUs, maxCloudVUs)\n}","typeGuard":null,"tryCatchPattern":"if _, err := c.StartLocalExecution(ctx, id, req); err != nil {\n\tif strings.Contains(err.Error(), \"max_vus\") && strings.Contains(err.Error(), \"overflows int32\") {\n\t\t// input bug, not transient: fix how MaxVUs is computed (sentinels/units)\n\t\treturn fmt.Errorf(\"computed max_vus=%d is invalid; check scenario VU totals\", req.MaxVUs)\n\t}\n}","preventionTips":["Compute MaxVUs from scenario definitions, never from untrusted arithmetic.","Outlaw -1/0 sentinels in request structs — use pointers or explicit optional fields.","Range-check all numeric request fields at the construction boundary."],"tags":["k6","cloud","provisioning","integer-overflow","validation","max-vus"],"backgroundTag":"integer-overflow","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}