{"record":{"id":"d00e8530201583f3","repo":"ipfs/kubo","slug":"err-error-d00e85","errorCode":null,"errorMessage":"err.Error()","messagePattern":"err\\.Error\\(\\)","errorType":"http","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"core/corehttp/mutex_profile.go","lineNumber":22,"sourceCode":"\t\"net\"\n\t\"net/http\"\n\t\"runtime\"\n\t\"strconv\"\n\n\tcore \"github.com/ipfs/kubo/core\"\n)\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","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/corehttp/mutex_profile.go#L4-L40","documentation":"The mutex-fraction endpoint parses the request body with r.ParseForm before reading the 'fraction' parameter. If the request body is malformed for form parsing (bad Content-Type, truncated body, invalid encoding), it returns HTTP 400 with the raw parse error text in the body.","triggerScenarios":"POSTing to the mutex-fraction debug path with a body that cannot be parsed as a form — e.g. sending JSON without application/x-www-form-urlencoded or multipart/form-data, a corrupted/chunked body, or invalid URL encoding in the query/body.","commonSituations":"Scripts sending `--data` with JSON to the endpoint; clients setting the wrong Content-Type header; URL-encoded values containing invalid percent sequences; proxies mangling the request body.","solutions":["Send the parameter as a proper form body: `curl -X POST -d 'fraction=5' <debug-path>` (curl sets application/x-www-form-urlencoded).","Ensure the Content-Type is application/x-www-form-urlencoded or multipart/form-data when POSTing manually.","URL-encode parameter values correctly; avoid raw special characters in the fraction field.","Verify no proxy/middleware is truncating or rewriting the request body."],"exampleFix":"// before: JSON body cannot be form-parsed\ncurl -X POST -H 'Content-Type: application/json' -d '{\"fraction\":5}' <debug-path>  // 400\n\n// after\ncurl -X POST -d 'fraction=5' <debug-path>","handlingStrategy":"validation","validationCode":"form := url.Values{\"fraction\": {\"5\"}}\nreq, _ := http.NewRequest(http.MethodPost, debugURL, strings.NewReader(form.Encode()))\nreq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n// body is guaranteed parseable by r.ParseForm","typeGuard":null,"tryCatchPattern":"resp, err := http.DefaultClient.Do(req)\nif err == nil && resp.StatusCode == http.StatusBadRequest {\n    body, _ := io.ReadAll(resp.Body)\n    // body contains the ParseForm error; fix Content-Type/encoding and resend\n    return fmt.Errorf(\"form rejected: %s\", body)\n}","preventionTips":["Always POST as application/x-www-form-urlencoded (curl -d does this automatically).","Never send JSON bodies to this endpoint; it uses r.ParseForm.","URL-encode all parameter values; invalid percent encodings fail ParseForm.","Check proxies/middleware that rewrite or truncate request bodies."],"tags":["http","bad-request","form-parse","debug"],"backgroundTag":"malformed-request-body","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"}