golang/go · error

server response: %s

Error message

server response: %s

What it means

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.

Source

Thrown at src/cmd/pprof/pprof.go:118

	resp, err := client.Get(source)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return nil, statusCodeError(resp)
	}
	return profile.Parse(resp.Body)
}

func statusCodeError(resp *http.Response) error {
	if resp.Header.Get("X-Go-Pprof") != "" && strings.Contains(resp.Header.Get("Content-Type"), "text/plain") {
		// error is from pprof endpoint
		if body, err := io.ReadAll(resp.Body); err == nil {
			return fmt.Errorf("server response: %s - %s", resp.Status, body)
		}
	}
	return fmt.Errorf("server response: %s", resp.Status)
}

// cpuProfileHandler is the Go pprof CPU profile handler URL.
const cpuProfileHandler = "/debug/pprof/profile"

// adjustURL applies the duration/timeout values and Go specific defaults.
func adjustURL(source string, duration, timeout time.Duration) (string, time.Duration) {
	u, err := url.Parse(source)
	if err != nil || (u.Host == "" && u.Scheme != "" && u.Scheme != "file") {
		// Try adding http:// to catch sources of the form hostname:port/path.
		// url.Parse treats "hostname" as the scheme.
		u, err = url.Parse("http://" + source)
	}
	if err != nil || u.Host == "" {
		return "", 0
	}

	if u.Path == "" || u.Path == "/" {

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Verify the URL is correct and the server is reachable — check with `curl -v <url>` to inspect the full response.
  2. If behind a proxy or load balancer, ensure the profiling endpoint is accessible and not blocked by routing rules.
  3. Add authentication credentials if the endpoint requires them — use the appropriate URL scheme or headers.
  4. Confirm the target is actually a Go application with pprof enabled, not a different service on the same port.
  5. Check for network issues (firewall, DNS) if the status indicates connection-level problems.

Example fix

# Before: wrong URL or port
pprof http://localhost:8080/debug/pprof/profile

# After: correct port and path
pprof http://localhost:6060/debug/pprof/profile

# Verify with curl first
curl -v http://localhost:6060/debug/pprof/
Defensive patterns

Strategy: validation

Validate before calling

// Validate endpoint before fetching profile:
resp, err := http.Head(url)
if err != nil {
    return fmt.Errorf("endpoint unreachable: %w", err)
}
if resp.StatusCode != 200 {
    return fmt.Errorf("endpoint returned %s; verify URL and server", resp.Status)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/649797019abef926. Report an issue: GitHub.