{"record":{"id":"60b05858334228dc","repo":"golang/go","slug":"server-response-s-s","errorCode":null,"errorMessage":"server response: %s - %s","messagePattern":"server response: (.+?) - (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/pprof/pprof.go","lineNumber":115,"sourceCode":"\t\t\tTLSClientConfig:       tlsConfig,\n\t\t},\n\t}\n\tresp, err := client.Get(source)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer resp.Body.Close()\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, statusCodeError(resp)\n\t}\n\treturn profile.Parse(resp.Body)\n}\n\nfunc statusCodeError(resp *http.Response) error {\n\tif resp.Header.Get(\"X-Go-Pprof\") != \"\" && strings.Contains(resp.Header.Get(\"Content-Type\"), \"text/plain\") {\n\t\t// error is from pprof endpoint\n\t\tif body, err := io.ReadAll(resp.Body); err == nil {\n\t\t\treturn fmt.Errorf(\"server response: %s - %s\", resp.Status, body)\n\t\t}\n\t}\n\treturn fmt.Errorf(\"server response: %s\", resp.Status)\n}\n\n// cpuProfileHandler is the Go pprof CPU profile handler URL.\nconst cpuProfileHandler = \"/debug/pprof/profile\"\n\n// adjustURL applies the duration/timeout values and Go specific defaults.\nfunc adjustURL(source string, duration, timeout time.Duration) (string, time.Duration) {\n\tu, err := url.Parse(source)\n\tif err != nil || (u.Host == \"\" && u.Scheme != \"\" && u.Scheme != \"file\") {\n\t\t// Try adding http:// to catch sources of the form hostname:port/path.\n\t\t// url.Parse treats \"hostname\" as the scheme.\n\t\tu, err = url.Parse(\"http://\" + source)\n\t}\n\tif err != nil || u.Host == \"\" {\n\t\treturn \"\", 0","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/pprof/pprof.go#L97-L133","documentation":"The pprof tool received a non-200 HTTP response from a pprof endpoint, and the response included both an `X-Go-Pprof` header and a `text/plain` content type. This indicates the error came from a Go pprof handler (which sets these headers on errors). The error message includes both the HTTP status line and the response body text, giving the server-side error reason.","triggerScenarios":"Fires in `statusCodeError` at pprof.go:111-116 when `fetchURL` (or similar HTTP fetch) gets a response with `StatusCode != http.StatusOK`, the response has `X-Go-Pprof` header set, and the Content-Type contains `text/plain`. The body is read successfully. This occurs when querying a Go application's `/debug/pprof/` endpoint that returns an error.","commonSituations":"Querying a pprof endpoint for a profile type that isn't enabled or doesn't exist (e.g., heap profile when the app hasn't allocated enough). The server's pprof handler encountered an internal error while generating the profile. Requesting a profile with invalid parameters (e.g., `seconds=0` for CPU profile). The Go application is running an older version whose pprof handler doesn't support the requested profile type. Rate limiting or server-side errors on the profiling endpoint.","solutions":["Read the body text in the error message — it contains the server's explanation of what went wrong.","Verify the pprof endpoint URL is correct and the profile type exists (e.g., /debug/pprof/heap, /debug/pprof/profile, /debug/pprof/goroutine).","Ensure the target Go application has `net/http/pprof` imported and the pprof endpoints are registered.","Check that the profile duration parameter is valid (e.g., use `pprof -seconds=30 http://host/debug/pprof/profile`).","If the server-side error is unclear, check the application's own logs for the corresponding error."],"exampleFix":"# Before: requesting with invalid parameters\npprof http://localhost:6060/debug/pprof/profile?seconds=0\n\n# After: use valid duration\npprof -seconds=30 http://localhost:6060/debug/pprof/profile\n\n# Ensure pprof is registered in the target app:\n# import _ \"net/http/pprof\"","handlingStrategy":"try-catch","validationCode":"// Before fetching a pprof profile, verify the endpoint is reachable\n// and returns expected headers:\nresp, err := http.Get(url)\nif err != nil {\n    return err\n}\nif resp.StatusCode != 200 {\n    // check X-Go-Pprof header to distinguish Go pprof errors\n    if resp.Header.Get(\"X-Go-Pprof\") != \"\" {\n        body, _ := io.ReadAll(resp.Body)\n        return fmt.Errorf(\"pprof endpoint error: %s\", body)\n    }\n    return fmt.Errorf(\"HTTP %d\", resp.StatusCode)\n}","typeGuard":null,"tryCatchPattern":"// When using go tool pprof, wrap with error checking:\n// pprof's fetchURL already handles this; ensure your pprof endpoint\n// is correctly configured in the target app:\n//   import _ \"net/http/pprof\"\n//   go http.ListenAndServe(\"localhost:6060\", nil)","preventionTips":["Always import `_ \"net/http/pprof\"` in the target Go application to register pprof endpoints.","Verify the endpoint with curl before using pprof: `curl http://host:port/debug/pprof/`.","Use valid profile durations: `pprof -seconds=30 url`.","Check the application logs if the pprof endpoint returns an error."],"tags":["pprof","http","profiling","network","debug-endpoint"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}