chenhg5/cc-connect · error

range chunk retries exhausted

Error message

range chunk retries exhausted

What it means

resourceRangeChunk performs HTTP Range requests to fetch one chunk of a large resource, retrying on failure. When every attempt for a chunk fails (or the retry loop exits with no recorded error), it wraps the last error in 'range chunk retries exhausted', signaling that the chunk could not be downloaded after all retries. Callers (resourceFetchRemainingChunks) surface this as the download failing for the resource.

Source

Thrown at platform/feishu/resource_download.go:379

		_ = resp.Body.Close()

		if resp.StatusCode >= 500 && resp.StatusCode < 600 && attempt < maxTransientRetries {
			lastErr = fmt.Errorf("range status %d body=%q", resp.StatusCode, strings.TrimSpace(string(body)))
			continue
		}

		if resp.StatusCode >= 200 && resp.StatusCode < 300 && end-start+1 == int64(len(body)) {
			// Server ignored Range and returned a 200 with exactly the bytes
			// we wanted — fine for the last chunk of a file, slightly off for
			// non-tail chunks. Caller decides; we return what we got.
			return body, nil
		}

		return nil, fmt.Errorf("range request status=%d body=%q", resp.StatusCode, strings.TrimSpace(string(body)))
	}

	if lastErr == nil {
		lastErr = errors.New("range chunk retries exhausted")
	}
	return nil, fmt.Errorf("range chunk retries exhausted: %w", lastErr)
}

// defaultResourceChunkSize returns the chunk size used when a Platform is
// constructed without going through newPlatform (tests, manual fixtures).
// Matches the production default of 8 MiB.
func defaultResourceChunkSize() int64 { return 8 * 1024 * 1024 }

// fetchResourceTokenOrDefault returns the bearer token used for resource
// downloads. Tests can inject a stub via Platform.fetchResourceToken;
// production callers fall through to fetchFreshTenantAccessToken which uses
// the lark SDK to mint a fresh tenant token on demand.
func (p *Platform) fetchResourceTokenOrDefault(ctx context.Context) (string, error) {
	if p.fetchResourceToken != nil {
		return p.fetchResourceToken(ctx)
	}
	return p.fetchFreshTenantAccessToken(ctx)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Retry the whole resource download later — transient network/server errors are the most common cause.
  2. Check that the HTTP server serving the resource supports Range requests (Accept-Ranges: bytes) and honors If-Range/ETag semantics.
  3. Reduce chunk size or concurrency if the server throttles or drops large/range-heavy transfers.
  4. Inspect the wrapped lastErr in the message (e.g. 'range request status=416') to address the underlying cause specifically.

Example fix

// before (server without range support)
resp to 'Range: bytes=...' returns 200 full-body -> chunk parse fails each retry
// after
serve with Accept-Ranges: bytes and honor Range headers, or download whole file without chunking
Defensive patterns

Strategy: retry

Validate before calling

resp, err := http.Head(resourceURL)
if err != nil || !strings.Contains(resp.Header.Get("Accept-Ranges"), "bytes") {
    log.Warn("server may not support Range requests; chunked download will likely fail", "url", resourceURL)
}

Try / catch

data, err := resourceDownload(ctx, url)
if strings.Contains(err.Error(), "retries exhausted") {
    // surface wrapped cause and back off before retriggering
    log.Error("resource download failed after retries", "cause", err, "retry_in", 5*time.Minute)
    time.Sleep(5 * time.Minute)
    data, err = resourceDownload(ctx, url)
}

Prevention

When it happens

Trigger: Raised when the Range GET repeatedly returns non-2xx statuses (e.g. status=416 for out-of-range offsets, 5xx server errors), the connection drops mid-chunk, or the loop's attempt counter is exhausted while lastErr remains nil.

Common situations: Transferring large files over flaky networks; servers that do not properly support Range requests and return 200/416; CDN timeouts on large offsets; source file changing size between the initial request and chunk fetches (416).

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


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