{"record":{"id":"8390cccdd839d82f","repo":"grafana/k6","slug":"generating-idempotency-key-w","errorCode":null,"errorMessage":"generating idempotency key: %w","messagePattern":"generating idempotency key: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloudapi/provisioning/api.go","lineNumber":195,"sourceCode":"\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\treturn ctx.Err()\n\t\tcase <-time.After(pollInterval):\n\t\t\t// continue polling\n\t\t}\n\t}\n}\n\n// StartLocalExecution starts a local-execution test run via the\n// provisioning API. It generates a K6-Idempotency-Key header for\n// 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)","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/cloudapi/provisioning/api.go#L177-L213","documentation":"Returned by Client.StartLocalExecution (internal/cloudapi/provisioning/api.go:195) when crypto/rand.Read fails while generating the 8 random bytes for the K6-Idempotency-Key header. The Go standard library's rand.Read essentially never fails on modern operating systems; when it does, the system's entropy source (/dev/urandom or getrandom(2)) is unavailable or broken in the execution environment. No network call has happened yet when this fires.","triggerScenarios":"crypto/rand.Read returning an error: containers/VMs with /dev/urandom missing or not yet initialized (very early boot), restricted sandbox/seccomp profiles blocking getrandom, or test code having replaced the crypto/rand Reader with one that errors.","commonSituations":"Minimal container images (distroless/scratch variants with broken device nodes); heavily sandboxed CI executors; Go tests overriding rand.Reader; ancient kernels without getrandom support.","solutions":["Verify /dev/urandom exists and is readable inside the environment: 'ls -l /dev/urandom && head -c 8 /dev/urandom | xxd'.","If running a minimal container, ensure device nodes are set up (proper --device /tmpfs or init system) or use a fuller base image.","Relax the sandbox/seccomp profile to allow the getrandom syscall.","In tests, stop overriding crypto/rand.Reader with an erroring stub, or make the stub succeed."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Environment pre-flight: crypto/rand must be readable.\nfunc entropyAvailable() bool {\n\tb := make([]byte, 8)\n\t_, err := rand.Read(b)\n\treturn err == nil\n}","typeGuard":null,"tryCatchPattern":"if _, err := c.StartLocalExecution(ctx, id, req); err != nil && strings.Contains(err.Error(), \"generating idempotency key\") {\n\t// entropy source broken — fixing the environment is the only cure; a retry cannot succeed\n\treturn fmt.Errorf(\"system entropy source unavailable; check /dev/urandom in this container: %w\", err)\n}","preventionTips":["In minimal containers, verify /dev/urandom exists before running k6.","Allow the getrandom syscall in seccomp/sandbox profiles.","In Go tests, keep crypto/rand.Reader real or make stubs succeed."],"tags":["k6","cloud","provisioning","crypto-rand","entropy","idempotency-key"],"backgroundTag":"crypto-rand-read-failure","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"}