{"record":{"id":"0664e7e013064b6b","repo":"juicedata/juicefs","slug":"error-get-request-v","errorCode":null,"errorMessage":"error GET request: %v","messagePattern":"error GET request: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/debug.go","lineNumber":231,"sourceCode":"\t\t}\n\t}\n\n\tif listenPort == -1 {\n\t\treturn 0, fmt.Errorf(\"no valid pprof port found\")\n\t}\n\treturn listenPort, nil\n}\n\nfunc getRequest(url string, timeout time.Duration) ([]byte, error) {\n\tctx, cancel := context.WithTimeout(context.Background(), timeout)\n\tdefer cancel()\n\treq, err := http.NewRequestWithContext(ctx, \"GET\", url, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error creating GET request: %v\", err)\n\t}\n\tresp, err := http.DefaultClient.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error GET request: %v\", err)\n\t}\n\tif resp.StatusCode != 200 {\n\t\treturn nil, fmt.Errorf(\"error GET request, status code %d\", resp.StatusCode)\n\t}\n\n\tdefer func(body io.ReadCloser) {\n\t\tif err := body.Close(); err != nil {\n\t\t\tlogger.Errorf(\"error closing body: %v\", err)\n\t\t}\n\t}(resp.Body)\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error reading response: %v\", err)\n\t}\n\n\treturn body, nil\n}\n","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/cmd/debug.go#L213-L249","documentation":"getRequest issues the request with http.DefaultClient.Do; any transport-level failure — connection refused, DNS failure, timeout (context deadline exceeded), TLS error — is wrapped as 'error GET request: %v'. The request was created successfully but never completed successfully at the network layer.","triggerScenarios":"Called from checkPort (probing localhost:<port>/debug/pprof/cmdline with a 3s timeout) and reqAndSaveMetric (metric/profile URLs) when: the pprof listener is not actually up on that port, the connection is refused/times out, or the metric endpoint host is unreachable.","commonSituations":"A stale lsof-derived port belongs to a socket that just closed; pprof is listening on IPv6 only and localhost resolves oddly; a 3s timeout is too short on a heavily loaded client (context deadline exceeded); remote metric hosts behind firewalls/VPN drops.","solutions":["Verify the endpoint manually: `curl -m 3 http://localhost:<port>/debug/pprof/cmdline?debug=1` and compare the failure.","If the error is `context deadline exceeded`, increase the timeout argument passed to getRequest / reqAndSaveMetric.","If connection refused, confirm the process is still alive and listening on that port (`ss -ltnp | grep <pid>`), then rerun `juicefs debug`.","Check proxy environment variables (HTTP_PROXY/HTTPS_PROXY) which http.DefaultClient honors and which can break localhost requests.","Test metric URLs (prometheus/grafana endpoints) reachability and DNS from the same host."],"exampleFix":"// before\nresp, err := getRequest(\"http://localhost:6060/debug/pprof/heap?debug=1\", 3*time.Second)\n// after\nfor i := 0; i < 3; i++ {\n    resp, err = getRequest(url, 3*time.Second)\n    if err == nil { break }\n    time.Sleep(500 * time.Millisecond)\n}","handlingStrategy":"retry","validationCode":"conn, err := net.DialTimeout(\"tcp\", fmt.Sprintf(\"localhost:%d\", port), 2*time.Second)\nif err != nil {\n    return fmt.Errorf(\"pprof port %d not reachable: %v\", port, err)\n}\nconn.Close()","typeGuard":null,"tryCatchPattern":"var body []byte\nvar err error\nfor i := 0; i < 3; i++ {\n    body, err = getRequest(url, 5*time.Second)\n    if err == nil { break }\n    var ne net.Error\n    if errors.As(err, &ne) && ne.Timeout() {\n        time.Sleep(time.Second) // retry only transient timeouts\n        continue\n    }\n    break // connection refused etc. — don't retry blindly\n}","preventionTips":["Use a timeout generous enough for loaded clients (default 3s may be too tight).","Set NO_PROXY for localhost so http.DefaultClient doesn't route loopback through a proxy.","Confirm the target process is alive and listening before probing (ss/lsof).","Distinguish timeout (retryable) from connection-refused (fix target) when handling the wrapped error."],"tags":["go","http","network","timeout"],"backgroundTag":"http-request-failed","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}