flipped-aurora/gin-vue-admin · error
读取大模型响应失败: %w
Error message
读取大模型响应失败: %w
What it means
LLMAuto reads the full HTTP response body with io.ReadAll after the request succeeded; if that read fails (connection reset mid-response, context deadline while streaming, truncated chunked body), this message wraps the read error. It signals the response was received but could not be fully drained.
Source
Thrown at server/service/system/auto_code_llm.go:39
return nil, err
}
res, err := request.HttpRequestWithContextAndTimeout(
ctx,
path,
http.MethodPost,
nil,
nil,
llm,
)
if err != nil {
return nil, fmt.Errorf("调用上游大模型服务失败: %w", err)
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("读取大模型响应失败: %w", err)
}
bodyPreview := previewResponseBody(body)
contentType := res.Header.Get("Content-Type")
if res.StatusCode < 200 || res.StatusCode >= 300 {
return nil, fmt.Errorf("上游大模型服务返回非 2xx: status=%d content-type=%s body=%s", res.StatusCode, contentType, bodyPreview)
}
var resStruct commonResp.Response
if err = json.Unmarshal(body, &resStruct); err != nil {
return nil, fmt.Errorf("解析大模型响应失败: status=%d content-type=%s body=%s err=%w", res.StatusCode, contentType, bodyPreview, err)
}
if resStruct.Code != commonResp.SUCCESS {
return nil, fmt.Errorf("大模型服务返回业务错误: code=%d msg=%s body=%s", resStruct.Code, resStruct.Msg, bodyPreview)
}
return resStruct.Data, nilView on GitHub (pinned to 3136500ef3)
Solutions
- Increase the client/context timeout to accommodate slow LLM responses
- Check intermediary proxies/LB idle-timeout settings and raise them above the LLM latency
- Retry the request; transient mid-body resets are often one-off
- Inspect the wrapped error to distinguish context deadline vs connection reset
Defensive patterns
Strategy: retry
Try / catch
var body []byte
var lastErr error
for attempt := 0; attempt < 3; attempt++ {
body, lastErr = attemptRead(ctx, llmCfg)
if lastErr == nil { break }
time.Sleep(time.Duration(1<<attempt) * time.Second)
}
if lastErr != nil { return lastErr } Prevention
- Raise client/context timeout above worst-case LLM latency
- Raise proxy/LB idle timeouts for long-running LLM endpoints
- Prefer stable networks for code-gen workloads; avoid reading huge bodies over flaky links
- Wrap reads with a bounded retry for transient resets
When it happens
Trigger: io.ReadAll(res.Body) returns non-nil err after a 2xx-or-not HTTP response — typically the upstream closed the connection mid-body or the request context timed out while the body was being read.
Common situations: LLM gateway/proxy (nginx, cloud LB) with short idle timeouts killing slow responses, large responses over unstable networks, server-side crash mid-response, context deadline hit during a slow LLM generation.
Related errors
- 上游大模型流式服务返回非 2xx: status=%d content-type=%s read-body-err=%w
- 上游大模型流式服务返回非 2xx: status=%d content-type=%s body=%s
- 调用上游大模型失败: %w
- 上游大模型流式服务返回非 2xx: status=%d content-type=%s read-body-err=%w
- 调用上游大模型服务失败: %w
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/12bda803d3dd7a25.
Report an issue: GitHub.