jeessy2/ddns-go · error

读取 dnsla 记录列表响应失败: %w

Error message

读取 dnsla 记录列表响应失败: %w

What it means

This error is returned when io.ReadAll fails while reading the dnsla API response body after a successful HTTP call. This is rare because the body is fully buffered by the client, and typically indicates the connection was reset mid-response or a custom http.Client Transport/ResponseWriter misbehaved.

Source

Thrown at dns/dnsla.go:279

	}

	byteBuff := []byte(dnsla.DNS.ID + ":" + dnsla.DNS.Secret)
	token := "Basic " + base64.StdEncoding.EncodeToString(byteBuff)
	// 设置 Headers
	req.Header.Set("Authorization", token)

	// 发送请求
	client := dnsla.httpClient
	resp, err := client.Do(req)
	if err != nil {
		return nil, fmt.Errorf("请求 dnsla 记录列表失败: %w", err)
	}
	defer resp.Body.Close()

	// 读取响应
	result, err = io.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("读取 dnsla 记录列表响应失败: %w", err)
	}
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("dnsla 记录列表请求失败,状态码: %d, 响应: %s", resp.StatusCode, string(result))
	}
	return result, nil
}

View on GitHub (pinned to 5874c2e666)

Solutions

  1. Retry the request — this is usually transient
  2. Check the wrapped error message for 'connection reset' or 'unexpected EOF' to confirm mid-stream drop
  3. Increase the http.Client Timeout if the response is large and the timeout cuts reads
  4. Rule out proxies/load balancers terminating idle or long connections

Example fix

// before
result, err = io.ReadAll(resp.Body)
if err != nil {
    return nil, fmt.Errorf("读取 dnsla 记录列表响应失败: %w", err)
}
// after
result, err = io.ReadAll(resp.Body)
if err != nil {
    return nil, fmt.Errorf("读取 dnsla 记录列表响应失败 (status=%d): %w", resp.StatusCode, err)
}
Defensive patterns

Strategy: retry

Type guard

func isTransientIOErr(err error) bool {
    return errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, syscall.ECONNRESET)
}

Try / catch

records, err := getRecordList(...)
if err != nil {
    if strings.Contains(err.Error(), "unexpected EOF") || strings.Contains(err.Error(), "connection reset") {
        // 瞬时错误,重试一次
        records, err = getRecordList(...)
    }
    if err != nil {
        return err
    }
}

Prevention

When it happens

Trigger: io.ReadAll(resp.Body) returns an error: server closed the connection before sending the full body, chunked encoding interrupted, or a custom http.Transport / interceptor returning an erroring body reader.

Common situations: Unstable network dropping long responses; dnsla API gateway cutting connections; wrapping client (e.g. debug middleware) providing a failing body; response body read after a timeout set on the client aborted mid-read.

Related errors


AI-assisted analysis of jeessy2/ddns-go@5874c2e666 (2026-09-03). Data as JSON: /api/errors/c88dbec3133a72a2. Report an issue: GitHub.