chenhg5/cc-connect · error

read body from %s: %w

Error message

read body from %s: %w

What it means

After a successful 200 response, the body is read with a 1 MiB cap (`io.LimitReader(resp.Body, 1<<20)`). This error wraps any I/O failure while reading the response stream — the connection dropped mid-transfer, or an intermediate proxy truncated the response.

Source

Thrown at core/provider_presets.go:150

	return c.data, nil
}

func fetchPresetsFromURL(url string, timeout time.Duration) (*ProviderPresetsResponse, error) {
	slog.Debug("fetching provider presets", "url", url)
	client := &http.Client{Timeout: timeout}
	resp, err := client.Get(url)
	if err != nil {
		return nil, fmt.Errorf("HTTP GET %s: %w", url, err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("HTTP GET %s: status %d", url, resp.StatusCode)
	}

	body, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
	if err != nil {
		return nil, fmt.Errorf("read body from %s: %w", url, err)
	}

	var result ProviderPresetsResponse
	if err := json.Unmarshal(body, &result); err != nil {
		return nil, fmt.Errorf("parse JSON from %s: %w", url, err)
	}
	return &result, nil
}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Retry the fetch — transient connection resets usually succeed on a second attempt.
  2. Check for proxies/load balancers between the client and server and raise their body/idle timeouts.
  3. Serve the presets from a more reliable host or CDN.
  4. Fall back to the stale cache (`c.data`) when a fresh fetch fails mid-body, which the fetch caller already does.
Defensive patterns

Strategy: retry

Try / catch

body, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
if err != nil {
    slog.Warn("presets body read failed, will retry/fall back", "url", url, "error", err)
    return retryOrStale()
}

Prevention

When it happens

Trigger: Calling fetchPresetsFromURL where `io.ReadAll` on the limited body returns an error: server resets the connection mid-body, read timeout firing during body transfer, or proxy interruption.

Common situations: Flaky mobile/satellite links; load balancers with aggressive idle timeouts; proxies that kill long-running body streams; extremely large responses hitting infrastructure limits and getting cut off.

Related errors


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