golang/go · error

server response: %s - %s

Error message

server response: %s - %s

What it means

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.

Source

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

			TLSClientConfig:       tlsConfig,
		},
	}
	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

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Read the body text in the error message — it contains the server's explanation of what went wrong.
  2. Verify the pprof endpoint URL is correct and the profile type exists (e.g., /debug/pprof/heap, /debug/pprof/profile, /debug/pprof/goroutine).
  3. Ensure the target Go application has `net/http/pprof` imported and the pprof endpoints are registered.
  4. Check that the profile duration parameter is valid (e.g., use `pprof -seconds=30 http://host/debug/pprof/profile`).
  5. If the server-side error is unclear, check the application's own logs for the corresponding error.

Example fix

# Before: requesting with invalid parameters
pprof http://localhost:6060/debug/pprof/profile?seconds=0

# After: use valid duration
pprof -seconds=30 http://localhost:6060/debug/pprof/profile

# Ensure pprof is registered in the target app:
# import _ "net/http/pprof"
Defensive patterns

Strategy: try-catch

Validate before calling

// Before fetching a pprof profile, verify the endpoint is reachable
// and returns expected headers:
resp, err := http.Get(url)
if err != nil {
    return err
}
if resp.StatusCode != 200 {
    // check X-Go-Pprof header to distinguish Go pprof errors
    if resp.Header.Get("X-Go-Pprof") != "" {
        body, _ := io.ReadAll(resp.Body)
        return fmt.Errorf("pprof endpoint error: %s", body)
    }
    return fmt.Errorf("HTTP %d", resp.StatusCode)
}

Try / catch

// When using go tool pprof, wrap with error checking:
// pprof's fetchURL already handles this; ensure your pprof endpoint
// is correctly configured in the target app:
//   import _ "net/http/pprof"
//   go http.ListenAndServe("localhost:6060", nil)

Prevention

When it happens

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

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

Related errors


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