jeessy2/ddns-go · error
读取响应失败: %v
Error message
读取响应失败: %v
What it means
dns/nowcn.go wraps the io.ReadAll(resp.Body) failure that occurs inside the shared request() helper (used by create, modify, getRecordList). It means the Nowcn API responded but the response body could not be read, usually because the connection dropped mid-response. The underlying io error is embedded in the message with %v.
Source
Thrown at dns/nowcn.go:268
if err != nil {
return nil, fmt.Errorf("创建请求失败: %v", err)
}
// 设置请求头
req.Header.Set("Accept", "application/json")
// 发送请求
client := t.httpClient
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("请求失败: %v", err)
}
defer resp.Body.Close()
// 读取响应
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("读取响应失败: %v", err)
}
// 检查HTTP状态码
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("API请求失败,状态码: %d, 响应: %s", resp.StatusCode, string(body))
}
return body, nil
}
View on GitHub (pinned to 5874c2e666)
Solutions
- Retry the request; transient connection resets usually succeed on a second attempt
- Check network connectivity/proxy stability between the host and the Nowcn API
- Inspect the wrapped %v error to distinguish timeout vs connection reset
- Ensure the configured HTTP client has a sane timeout and retry policy
Example fix
// before
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("读取响应失败: %v", err)
}
// after (caller-side retry)
for i := 0; i < 3; i++ {
body, err := provider.getRecordList(domain)
if err == nil {
break
}
if strings.Contains(err.Error(), "读取响应失败") {
time.Sleep(time.Duration(i+1) * time.Second)
continue
}
return err
} Defensive patterns
Strategy: retry
Validate before calling
// preflight connectivity check
if _, err := http.Head("https://www.now.cn"); err != nil {
return fmt.Errorf("nowcn unreachable: %w", err)
} Try / catch
// Go: sentinel check + bounded retry
for i := 0; i < 3; i++ {
recs, err := provider.getRecordList(domain)
if err == nil {
return recs, nil
}
if !strings.Contains(err.Error(), "读取响应失败") {
return nil, err
}
time.Sleep(time.Duration(1<<i) * time.Second)
}
return nil, err Prevention
- Run DDNS updates on a stable connection; add retry with exponential backoff
- Set a generous but bounded HTTP client timeout
- Monitor network health before scheduled updates
When it happens
Trigger: Any Nowcn API call (create, modify, getRecordList) where the HTTP response body read fails: server closes the connection early, network timeout during body transfer, or TLS interruption while streaming the body.
Common situations: Flaky networks or VPNs between the client and the Nowcn API; server-side gateways closing keep-alive connections; very short read timeouts; proxies that terminate responses prematurely.
Related errors
AI-assisted analysis of jeessy2/ddns-go@5874c2e666 (2026-09-03).
Data as JSON: /api/errors/23ab86293f3c2214.
Report an issue: GitHub.