{"record":{"id":"8af3dc044a65297f","repo":"JuliusBrussee/caveman","slug":"githubapp-read-response-w","errorCode":null,"errorMessage":"githubapp: read response: %w","messagePattern":"githubapp: read response: %w","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":389,"sourceCode":"\t}\n\treq, err := http.NewRequestWithContext(ctx, method, target.String(), reader)\n\tif err != nil {\n\t\treturn 0, nil, fmt.Errorf(\"githubapp: build request: %w\", err)\n\t}\n\treq.Header.Set(\"Authorization\", authorization)\n\treq.Header.Set(\"Accept\", \"application/vnd.github+json\")\n\treq.Header.Set(\"X-GitHub-Api-Version\", \"2022-11-28\")\n\tif body != nil {\n\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t}\n\tresp, err := a.httpClient.Do(req)\n\tif err != nil {\n\t\treturn 0, nil, fmt.Errorf(\"githubapp: request failed: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\traw, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))\n\tif err != nil {\n\t\treturn resp.StatusCode, nil, fmt.Errorf(\"githubapp: read response: %w\", err)\n\t}\n\treturn resp.StatusCode, raw, nil\n}\n\n// parseRSAPrivateKey accepts a PKCS#1 (\"RSA PRIVATE KEY\") or PKCS#8\n// (\"PRIVATE KEY\") PEM — GitHub Apps download PKCS#1, but Cloud KMS / openssl\n// conversions emit PKCS#8, so we accept both.\nfunc parseRSAPrivateKey(pemBytes []byte) (*rsa.PrivateKey, error) {\n\tblock, _ := pem.Decode(pemBytes)\n\tif block == nil {\n\t\treturn nil, fmt.Errorf(\"githubapp: private key is not valid PEM\")\n\t}\n\tif key, err := x509.ParsePKCS1PrivateKey(block.Bytes); err == nil {\n\t\treturn key, nil\n\t}\n\tparsed, err := x509.ParsePKCS8PrivateKey(block.Bytes)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"githubapp: private key is neither PKCS#1 nor PKCS#8 RSA: %w\", err)","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L371-L407","documentation":"The HTTP request succeeded (a response was received) but reading the response body failed. do() reads up to 4 MiB via io.ReadAll(io.LimitReader(resp.Body, 4<<20)); this error wraps any read failure such as a mid-body connection reset, chunked-encoding corruption, or TLS truncation. Note the status code IS returned alongside the error, so callers can still inspect it.","triggerScenarios":"Calling any App method when the connection drops partway through the response body (load balancer idle timeout, GFW-style RST, keep-alive reuse of a closed socket), or the server sends a corrupted chunked stream.","commonSituations":"Flaky networks or mobile/VPN links; corporate proxies that buffer and truncate large responses; GitHub incidents interrupting streaming; HTTP/2 GOAWAY races under concurrency; long-lived client instances with stale idle connections.","solutions":["Retry the request — body-read failures are typically transient; use exponential backoff and respect resp.StatusCode availability.","Disable stale keep-alive reuse by configuring short IdleConnTimeout on the client transport, or call CloseIdleConnections periodically.","Check for a proxy in the path that truncates responses and bypass or fix it.","Check status.github.com / your GHE instance health if failures cluster in time."],"exampleFix":"// before\nstatus, raw, err := app.DoToken(ctx, tok, \"GET\", \"/repos/o/r\", nil)\nif err != nil { return err } // gives up on transient read failures\n// after\nvar lastErr error\nfor attempt := 0; attempt < 3; attempt++ {\n    status, raw, err = app.DoToken(ctx, tok, \"GET\", \"/repos/o/r\", nil)\n    if err == nil { break }\n    lastErr = err\n    time.Sleep(time.Duration(1<<attempt) * 100 * time.Millisecond)\n}\nif err != nil { return fmt.Errorf(\"after retries: %w\", lastErr) }","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"status, raw, err := app.DoToken(ctx, tok, m, path, body)\nif err != nil {\n    // note: status code IS returned here; inspect it before retrying\n    if errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, io.EOF) {\n        // transient truncation: retry with backoff\n    }\n}","preventionTips":["Wrap calls in a small retry helper with exponential backoff.","Set sane transport IdleConnTimeout to avoid stale keep-alive sockets.","Monitor for correlated failures that indicate a proxy truncating responses.","Prefer idempotent GETs when designing retry logic."],"tags":["github","network","http-client","transient"],"backgroundTag":"network-request-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}