chenhg5/cc-connect · warning
googlechat: drain attachment create response body: %w
Error message
googlechat: drain attachment create response body: %w
What it means
After the attachment-create POST succeeds at the transport level, the platform drains the response body with io.Copy(io.Discard, ...). If reading the body fails (connection reset mid-response, context cancellation, TLS error), the body is closed and this wrapped error is returned.
Source
Thrown at platform/googlechat/googlechat.go:551
if err != nil {
return err
}
url, body, err := buildAttachmentRequest(rc, resourceName)
if err != nil {
return err
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body))
if err != nil {
return fmt.Errorf("googlechat: attachment message: build request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
resp, err := p.doRequest(req)
if err != nil {
return err
}
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
_ = resp.Body.Close()
return fmt.Errorf("googlechat: drain attachment create response body: %w", err)
}
if err := resp.Body.Close(); err != nil {
return fmt.Errorf("googlechat: close attachment create response body: %w", err)
}
return nil
}
// SendImage uploads an image and posts it as a Chat message attachment.
// Implements core.ImageSender.
func (p *Platform) SendImage(ctx context.Context, rctx any, img core.ImageAttachment) error {
rc, ok := rctx.(replyContext)
if !ok {
return fmt.Errorf("googlechat: SendImage: invalid reply context type %T", rctx)
}
return p.postAttachment(ctx, rc,
coalesce(img.FileName, "image.png"),
coalesce(img.MimeType, "image/png"),
img.Data)View on GitHub (pinned to 4000b2338a)
Solutions
- Retry the postAttachment call — the error is transient network-level
- Check proxy/firewall stability between the host and chat.googleapis.com
- Avoid cancelling the context while attachment sends are in flight
Defensive patterns
Strategy: retry
Try / catch
if err := p.SendImage(ctx, rc, img); err != nil {
if isTransientNetwork(err) { return retryWithBackoff(ctx, 3, func() error { return p.SendImage(ctx, rc, img) }) }
return err
} Prevention
- Ensure stable egress to chat.googleapis.com
- Avoid cancelling contexts mid-upload
- Monitor proxy keep-alive behavior
When it happens
Trigger: The Google Chat API connection drops while the response body is still being read; the request context is cancelled between receiving headers and draining the body.
Common situations: Unstable networks or proxies closing keep-alive connections early; callers cancelling the context during a slow upload; corporate proxies truncating responses.
Related errors
- googlechat: drain response body: %w
- googlechat: close response body: %w
- googlechat: send preview: %w
- range chunk retries exhausted
- request usage endpoint: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/8ac55779d878a50f.
Report an issue: GitHub.