chenhg5/cc-connect · error

first-chunk request: %w

Error message

first-chunk request: %w

What it means

Wraps an error from p.resourceDownloadHTTP.Do(req) during the first-chunk Range bytes=0-0 probe. This is a transport-level failure: connection refused/reset, DNS failure, TLS error, or the 5-second probe context deadline (resourceRangeProbeTimeout) expiring. The caller logs a warning and falls back to a plain single GET, which may also fail under the same network conditions.

Source

Thrown at platform/feishu/resource_download.go:150

		return first, nil
	}
	return p.resourceFetchRemainingChunks(ctx, token, messageID, fileKey, resType, total, first)
}

// resourceFetchFirstChunk issues Range bytes=0-0 to learn the total and grab
// the first byte. Returns (first, total, nil) where total==0 means the
// server ignored Range and the entire body is in `first`.
func (p *Platform) resourceFetchFirstChunk(ctx context.Context, token, messageID, fileKey, resType string) ([]byte, int64, error) {
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, p.resourceURL(messageID, fileKey, resType), nil)
	if err != nil {
		return nil, 0, fmt.Errorf("build first-chunk request: %w", err)
	}
	req.Header.Set("Authorization", "Bearer "+token)
	req.Header.Set("Range", "bytes=0-0")

	resp, err := p.resourceDownloadHTTP.Do(req)
	if err != nil {
		return nil, 0, fmt.Errorf("first-chunk request: %w", err)
	}
	defer func() { _, _ = io.Copy(io.Discard, resp.Body); _ = resp.Body.Close() }()

	switch resp.StatusCode {
	case http.StatusPartialContent:
		cr := resp.Header.Get("Content-Range")
		total, ok := parseContentRangeTotal(cr)
		if !ok {
			return nil, 0, fmt.Errorf("first-chunk: 206 without parseable Content-Range %q", cr)
		}
		body, err := io.ReadAll(io.LimitReader(resp.Body, 1))
		if err != nil {
			return nil, 0, fmt.Errorf("read first-chunk body: %w", err)
		}
		return body, total, nil

	case http.StatusOK:
		// Server ignored Range and sent the full body. We deliberately

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Check outbound network/DNS/TLS connectivity to the configured Feishu domain from the bot host
  2. If timeouts are frequent on slow networks, the plain-GET fallback path is used — fix underlying latency or increase probe budget in code
  3. Verify proxy env vars (HTTP_PROXY/HTTPS_PROXY) are correct if behind a corporate proxy
  4. Retry; transient network blips produce this error once and succeed on the next download

Example fix

null
Defensive patterns

Strategy: retry

Validate before calling

if err := net.DialTimeout("tcp", "open.feishu.cn:443", 3*time.Second); err != nil { skip("feishu unreachable") }

Type guard

null

Try / catch

data, err := downloadResourceChunked(ctx, ...)
if err != nil {
    var ne net.Error
    if errors.As(err, &ne) && ne.Timeout() { /* schedule retry with backoff */ }
}

Prevention

When it happens

Trigger: resourceDownloadHTTP.Do fails on the probe GET — network outage, DNS resolution failure, TLS handshake error, proxy misconfiguration, or probeCtx (5s) deadline exceeded before response headers arrive.

Common situations: Bot host loses connectivity mid-chat, corporate proxy blocking open.feishu.cn, slow Feishu CDN response exceeding the 5 s probe timeout on large-file hosts.

Related errors


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