chenhg5/cc-connect · error

%s: read: %w

Error message

%s: read: %w

What it means

Reading the CDN response body in fetchCdnBytes failed mid-stream (io.ReadAll over a LimitReader) — the connection was reset or timed out after headers were received, so the Weixin media download completed only partially.

Source

Thrown at platform/weixin/cdn.go:140

		url.QueryEscape(filekey))
}

func fetchCdnBytes(ctx context.Context, client *http.Client, fullURL, label string) ([]byte, error) {
	if client == nil {
		client = http.DefaultClient
	}
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, fullURL, nil)
	if err != nil {
		return nil, fmt.Errorf("%s: new request: %w", label, err)
	}
	resp, err := client.Do(req)
	if err != nil {
		return nil, fmt.Errorf("%s: get: %w", label, err)
	}
	defer resp.Body.Close()
	body, err := io.ReadAll(io.LimitReader(resp.Body, maxWeixinMediaBytes+1))
	if err != nil {
		return nil, fmt.Errorf("%s: read: %w", label, err)
	}
	if len(body) > maxWeixinMediaBytes {
		return nil, fmt.Errorf("%s: CDN body exceeds %d bytes", label, maxWeixinMediaBytes)
	}
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("%s: CDN http %d: %s", label, resp.StatusCode, truncateForLog(body, 256))
	}
	return body, nil
}

func downloadAndDecryptCDN(ctx context.Context, client *http.Client, cdnBase, encParam, aesKeyBase64, label string) ([]byte, error) {
	key, err := parseAesKey(aesKeyBase64, label)
	if err != nil {
		return nil, err
	}
	u := buildCdnDownloadURL(encParam, cdnBase)
	enc, err := fetchCdnBytes(ctx, client, u, label)
	if err != nil {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Retry the CDN download; partial reads are typically transient network resets
  2. Set/enforce client and read timeouts so a stalled body does not hang the media pipeline
  3. Discard partial data on failure — never forward truncated ciphertext to decryption
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at platform/weixin/cdn.go:140 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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