chenhg5/cc-connect · warning

googlechat: close response body: %w

Error message

googlechat: close response body: %w

What it means

This error is returned by the googlechat platform's internal post() helper when resp.Body.Close() fails after a successful HTTP response has been fully drained. The Go http package can report errors on close for responses with connection teardown issues; the library surfaces it wrapped with googlechat: context so callers know the message was likely delivered but cleanup failed. It propagates up through Reply and Send.

Source

Thrown at platform/googlechat/googlechat.go:439

	url, body, err := buildSendRequest(rc, content)
	if err != nil {
		return err
	}
	req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body))
	if err != nil {
		return fmt.Errorf("googlechat: 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 response body: %w", err)
	}
	if err := resp.Body.Close(); err != nil {
		return fmt.Errorf("googlechat: close response body: %w", err)
	}
	return nil
}

func (p *Platform) Reply(ctx context.Context, rctx any, content string) error {
	return p.post(ctx, rctx, content)
}

func (p *Platform) Send(ctx context.Context, rctx any, content string) error {
	return p.post(ctx, rctx, content)
}

// uploadAttachment uploads raw bytes to the Chat media endpoint using a
// multipart/related request and returns the attachmentDataRef resource name.
func (p *Platform) uploadAttachment(ctx context.Context, space, filename, mimeType string, data []byte) (string, error) {
	buf := bytes.NewBuffer(make([]byte, 0, 256+len(data)))
	mw := multipart.NewWriter(buf)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Retry the send; in most cases the message was already delivered and only body close failed.
  2. Check network stability/DNS/proxy settings between the host and googleapis.com.
  3. Upgrade the Go HTTP client/transport configuration (e.g. DisableKeepAlives) if close errors recur on connection reuse.
  4. Log and monitor occurrences — if frequent it indicates transport-level problems, not API misuse.
Defensive patterns

Strategy: retry

Try / catch

if err := p.Send(ctx, target, msg); err != nil {
    if strings.Contains(err.Error(), "close response body") {
        // message likely delivered; log at warn and continue
        slog.Warn("googlechat: response body close failed (likely delivered)", "err", err)
        return nil
    }
    return err
}

Prevention

When it happens

Trigger: Calling Reply() or Send() on the Google Chat platform; the POST to the Chat API succeeds, io.Copy(io.Discard, resp.Body) succeeds, but resp.Body.Close() returns a non-nil error (rare — typically connection reuse/teardown failure under flaky networks).

Common situations: Flaky network connections or HTTP/2 stream resets between the process and googleapis.com; proxy or firewall interference mid-response; client transport issues when the connection is returned to the pool.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/b9f416675cbdbe75. Report an issue: GitHub.