{"record":{"id":"81f2a61186bcfea4","repo":"chenhg5/cc-connect","slug":"first-chunk-request-w","errorCode":null,"errorMessage":"first-chunk request: %w","messagePattern":"first-chunk request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/feishu/resource_download.go","lineNumber":150,"sourceCode":"\t\treturn first, nil\n\t}\n\treturn p.resourceFetchRemainingChunks(ctx, token, messageID, fileKey, resType, total, first)\n}\n\n// resourceFetchFirstChunk issues Range bytes=0-0 to learn the total and grab\n// the first byte. Returns (first, total, nil) where total==0 means the\n// server ignored Range and the entire body is in `first`.\nfunc (p *Platform) resourceFetchFirstChunk(ctx context.Context, token, messageID, fileKey, resType string) ([]byte, int64, error) {\n\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, p.resourceURL(messageID, fileKey, resType), nil)\n\tif err != nil {\n\t\treturn nil, 0, fmt.Errorf(\"build first-chunk request: %w\", err)\n\t}\n\treq.Header.Set(\"Authorization\", \"Bearer \"+token)\n\treq.Header.Set(\"Range\", \"bytes=0-0\")\n\n\tresp, err := p.resourceDownloadHTTP.Do(req)\n\tif err != nil {\n\t\treturn nil, 0, fmt.Errorf(\"first-chunk request: %w\", err)\n\t}\n\tdefer func() { _, _ = io.Copy(io.Discard, resp.Body); _ = resp.Body.Close() }()\n\n\tswitch resp.StatusCode {\n\tcase http.StatusPartialContent:\n\t\tcr := resp.Header.Get(\"Content-Range\")\n\t\ttotal, ok := parseContentRangeTotal(cr)\n\t\tif !ok {\n\t\t\treturn nil, 0, fmt.Errorf(\"first-chunk: 206 without parseable Content-Range %q\", cr)\n\t\t}\n\t\tbody, err := io.ReadAll(io.LimitReader(resp.Body, 1))\n\t\tif err != nil {\n\t\t\treturn nil, 0, fmt.Errorf(\"read first-chunk body: %w\", err)\n\t\t}\n\t\treturn body, total, nil\n\n\tcase http.StatusOK:\n\t\t// Server ignored Range and sent the full body. We deliberately","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/feishu/resource_download.go#L132-L168","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check outbound network/DNS/TLS connectivity to the configured Feishu domain from the bot host","If timeouts are frequent on slow networks, the plain-GET fallback path is used — fix underlying latency or increase probe budget in code","Verify proxy env vars (HTTP_PROXY/HTTPS_PROXY) are correct if behind a corporate proxy","Retry; transient network blips produce this error once and succeed on the next download"],"exampleFix":"null","handlingStrategy":"retry","validationCode":"if err := net.DialTimeout(\"tcp\", \"open.feishu.cn:443\", 3*time.Second); err != nil { skip(\"feishu unreachable\") }","typeGuard":"null","tryCatchPattern":"data, err := downloadResourceChunked(ctx, ...)\nif err != nil {\n    var ne net.Error\n    if errors.As(err, &ne) && ne.Timeout() { /* schedule retry with backoff */ }\n}","preventionTips":["Ensure outbound HTTPS to the Feishu domain from the bot host (firewall/proxy allowlist)","Set HTTP_PROXY/HTTPS_PROXY correctly in daemon environments","Expect the 5 s probe timeout on slow networks; keep a retry at the application layer","Monitor connectivity health with a periodic lightweight API ping"],"tags":["go","feishu","network","timeout","http"],"backgroundTag":"network-request-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}