JuliusBrussee/caveman · error
githubapp: read response
Error message
githubapp: read response: %w
What it means
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.
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.
Example fix
// before
status, raw, err := app.DoToken(ctx, tok, "GET", "/repos/o/r", nil)
if err != nil { return err } // gives up on transient read failures
// after
var lastErr error
for attempt := 0; attempt < 3; attempt++ {
status, raw, err = app.DoToken(ctx, tok, "GET", "/repos/o/r", nil)
if err == nil { break }
lastErr = err
time.Sleep(time.Duration(1<<attempt) * 100 * time.Millisecond)
}
if err != nil { return fmt.Errorf("after retries: %w", lastErr) } Defensive patterns
Strategy: retry
Try / catch
status, raw, err := app.DoToken(ctx, tok, m, path, body)
if err != nil {
// note: status code IS returned here; inspect it before retrying
if errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, io.EOF) {
// transient truncation: retry with backoff
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- githubapp: request failed
- awscreds: request failed
- AbortError
- awscreds: build container credentials request
- awscreds: build imds token request
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/8af3dc044a65297f.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/githubapp/githubapp.go:389
}
req, err := http.NewRequestWithContext(ctx, method, target.String(), reader)
if err != nil {
return 0, nil, fmt.Errorf("githubapp: build request: %w", err)
}
req.Header.Set("Authorization", authorization)
req.Header.Set("Accept", "application/vnd.github+json")
req.Header.Set("X-GitHub-Api-Version", "2022-11-28")
if body != nil {
req.Header.Set("Content-Type", "application/json")
}
resp, err := a.httpClient.Do(req)
if err != nil {
return 0, nil, fmt.Errorf("githubapp: request failed: %w", err)
}
defer resp.Body.Close()
raw, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))
if err != nil {
return resp.StatusCode, nil, fmt.Errorf("githubapp: read response: %w", err)
}
return resp.StatusCode, raw, nil
}
// parseRSAPrivateKey accepts a PKCS#1 ("RSA PRIVATE KEY") or PKCS#8
// ("PRIVATE KEY") PEM — GitHub Apps download PKCS#1, but Cloud KMS / openssl
// conversions emit PKCS#8, so we accept both.
func parseRSAPrivateKey(pemBytes []byte) (*rsa.PrivateKey, error) {
block, _ := pem.Decode(pemBytes)
if block == nil {
return nil, fmt.Errorf("githubapp: private key is not valid PEM")
}
if key, err := x509.ParsePKCS1PrivateKey(block.Bytes); err == nil {
return key, nil
}
parsed, err := x509.ParsePKCS8PrivateKey(block.Bytes)
if err != nil {
return nil, fmt.Errorf("githubapp: private key is neither PKCS#1 nor PKCS#8 RSA: %w", err)View on GitHub (pinned to 3ee70a1026)