{"record":{"id":"649797019abef926","repo":"golang/go","slug":"server-response-s","errorCode":null,"errorMessage":"server response: %s","messagePattern":"server response: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/pprof/pprof.go","lineNumber":118,"sourceCode":"\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\n\t}\n\n\tif u.Path == \"\" || u.Path == \"/\" {","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/pprof/pprof.go#L100-L136","documentation":"The pprof tool received a non-200 HTTP response from a URL, and either the response did not have the `X-Go-Pprof` header / `text/plain` content type, or reading the response body failed. This is the fallback error that includes only the HTTP status line (e.g., '404 Not Found', '503 Service Unavailable') without the body text. This typically means the error came from a non-Go server, a proxy, or the response was not from a pprof endpoint.","triggerScenarios":"Fires in `statusCodeError` at pprof.go:118 as the fallback after the pprof-specific branch (line 112) is not taken. This happens when the response lacks the `X-Go-Pprof` header or the Content-Type isn't `text/plain`, or when `io.ReadAll` on the body returns an error.","commonSituations":"Pointing pprof at a wrong URL (404 Not Found). A reverse proxy or load balancer intercepting the request (502 Bad Gateway, 503 Service Unavailable). The server requires authentication (401 Unauthorized, 403 Forbidden). The URL points to a non-Go server that doesn't understand pprof requests. Connection reset or timeout during body read causing `io.ReadAll` to fail.","solutions":["Verify the URL is correct and the server is reachable — check with `curl -v <url>` to inspect the full response.","If behind a proxy or load balancer, ensure the profiling endpoint is accessible and not blocked by routing rules.","Add authentication credentials if the endpoint requires them — use the appropriate URL scheme or headers.","Confirm the target is actually a Go application with pprof enabled, not a different service on the same port.","Check for network issues (firewall, DNS) if the status indicates connection-level problems."],"exampleFix":"# Before: wrong URL or port\npprof http://localhost:8080/debug/pprof/profile\n\n# After: correct port and path\npprof http://localhost:6060/debug/pprof/profile\n\n# Verify with curl first\ncurl -v http://localhost:6060/debug/pprof/","handlingStrategy":"validation","validationCode":"// Validate endpoint before fetching profile:\nresp, err := http.Head(url)\nif err != nil {\n    return fmt.Errorf(\"endpoint unreachable: %w\", err)\n}\nif resp.StatusCode != 200 {\n    return fmt.Errorf(\"endpoint returned %s; verify URL and server\", resp.Status)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify the pprof URL and port with curl before using pprof.","Ensure no proxy or load balancer blocks access to the pprof endpoint.","Add authentication if the endpoint requires it.","Confirm the target service is actually a Go app with pprof enabled."],"tags":["pprof","http","network","profiling","connection-error"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}