chenhg5/cc-connect · warning

googlechat: drain update response body: %w

Error message

googlechat: drain update response body: %w

What it means

This error is returned by Platform.UpdateMessage in platform/googlechat/streaming.go when the response body of a Google Chat message-update HTTP request cannot be fully drained (io.Copy to io.Discard fails). Draining the body is required so the underlying TCP connection can be reused; a failure here indicates the response stream broke mid-read (connection reset, context cancellation, timeout). The original update may or may not have been applied server-side.

Source

Thrown at platform/googlechat/streaming.go:98

	if !ok {
		return fmt.Errorf("googlechat: invalid preview handle type %T", handle)
	}
	url, body, err := buildUpdateRequest(h.name, content)
	if err != nil {
		return err
	}
	req, err := http.NewRequestWithContext(ctx, http.MethodPatch, url, bytes.NewReader(body))
	if err != nil {
		return fmt.Errorf("googlechat: build update 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 update response body: %w", err)
	}
	if err := resp.Body.Close(); err != nil {
		return fmt.Errorf("googlechat: close update response body: %w", err)
	}
	return nil
}

var (
	_ core.MessageUpdater = (*Platform)(nil)
	_ core.PreviewStarter = (*Platform)(nil)
)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Retry UpdateMessage with backoff; the update is idempotent (same message ID and content).
  2. Check network stability / proxy configuration between the host and googleapis.com.
  3. Ensure the context passed into the request is not cancelled prematurely (e.g. short HTTP client timeouts).
  4. If it persists, inspect whether a body-size-limiting proxy or WAF is interfering with googleapis.com responses.
Defensive patterns

Strategy: retry

Try / catch

// Go: caller of UpdateMessage
for attempt := 0; attempt < 3; attempt++ {
    err := platform.UpdateMessage(ctx, msgID, content)
    if err == nil || !strings.Contains(err.Error(), "drain update response body") {
        break
    }
    time.Sleep(backoff(attempt))
}

Prevention

When it happens

Trigger: Calling UpdateMessage when the Google Chat API closes the connection before the response body finishes streaming, the request context is cancelled mid-read, or a proxy/load balancer truncates the response.

Common situations: Flaky networks or corporate proxies between the server and Google's API; long-lived streaming update loops hitting transient connection resets; request deadlines expiring during large responses.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


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