{"record":{"id":"29a366246b644d5e","repo":"ipfs/kubo","slug":"parameter-fraction-must-be-set","errorCode":null,"errorMessage":"parameter 'fraction' must be set","messagePattern":"parameter 'fraction' must be set","errorType":"http","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"core/corehttp/mutex_profile.go","lineNumber":28,"sourceCode":")\n\n// MutexFractionOption allows to set runtime.SetMutexProfileFraction via HTTP\n// using POST request with parameter 'fraction'.\nfunc MutexFractionOption(path string) ServeOption {\n\treturn func(_ *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {\n\t\tmux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {\n\t\t\tif r.Method != http.MethodPost {\n\t\t\t\thttp.Error(w, \"only POST allowed\", http.StatusMethodNotAllowed)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif err := r.ParseForm(); err != nil {\n\t\t\t\thttp.Error(w, err.Error(), http.StatusBadRequest)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tasfr := r.Form.Get(\"fraction\")\n\t\t\tif len(asfr) == 0 {\n\t\t\t\thttp.Error(w, \"parameter 'fraction' must be set\", http.StatusBadRequest)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tfr, err := strconv.Atoi(asfr)\n\t\t\tif err != nil {\n\t\t\t\thttp.Error(w, err.Error(), http.StatusBadRequest)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tlog.Infof(\"Setting MutexProfileFraction to %d\", fr)\n\t\t\truntime.SetMutexProfileFraction(fr)\n\t\t})\n\n\t\treturn mux, nil\n\t}\n}\n\n// BlockProfileRateOption allows to set runtime.SetBlockProfileRate via HTTP\n// using POST request with parameter 'rate'.","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/corehttp/mutex_profile.go#L10-L46","documentation":"After successfully parsing the form, the mutex-fraction endpoint requires a 'fraction' form parameter whose value sets runtime.SetMutexProfileFraction. If the parameter is absent or empty, it responds with HTTP 400 and the fixed message \"parameter 'fraction' must be set\".","triggerScenarios":"POSTing to the mutex-fraction debug path without a 'fraction' field — e.g. `curl -X POST <debug-path>` with no body, or `-d 'other=1'`, or an empty `-d 'fraction='`.","commonSituations":"Smoke-testing the endpoint with a bare POST; scripts renamed the parameter (e.g. 'value'); copying examples that omitted the body; empty-string values trimmed by the client.","solutions":["Include the parameter: `curl -X POST -d 'fraction=5' <debug-path>`.","Check the parameter name is exactly `fraction` (lowercase, singular).","Ensure the value is non-empty — `fraction=` still triggers the error.","Choose a sensible value: 0 disables mutex profiling; higher integers increase sampling detail."],"exampleFix":"// before\ncurl -X POST http://127.0.0.1:<debug-port>/debug/mutexfraction  // 400: parameter 'fraction' must be set\n\n// after\ncurl -X POST -d 'fraction=5' http://127.0.0.1:<debug-port>/debug/mutexfraction","handlingStrategy":"validation","validationCode":"fraction := \"5\"\nif fraction == \"\" {\n    return errors.New(\"fraction parameter must be set and non-empty\")\n}\nform := url.Values{\"fraction\": {fraction}}\nreq, _ := http.NewRequest(http.MethodPost, debugURL, strings.NewReader(form.Encode()))\nreq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")","typeGuard":null,"tryCatchPattern":"resp, err := http.DefaultClient.Do(req)\nif err == nil && resp.StatusCode == http.StatusBadRequest {\n    body, _ := io.ReadAll(resp.Body)\n    if strings.Contains(string(body), \"must be set\") {\n        return errors.New(\"add -d 'fraction=<int>' to the request\")\n    }\n    return fmt.Errorf(\"bad request: %s\", body)\n}","preventionTips":["Always include -d 'fraction=<int>' when POSTing to the mutex-fraction endpoint.","Use the exact lowercase parameter name `fraction`.","Reject empty values client-side before sending (`fraction=` triggers the error).","Encode parameters with url.Values in Go clients to guarantee presence."],"tags":["http","bad-request","missing-parameter","profiling"],"backgroundTag":"missing-request-parameter","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}