From 3a09d28ea3da184c55368de5f4e3a2f97867fad0 Mon Sep 17 00:00:00 2001 From: tsosunchia <59512455+tsosunchia@users.noreply.github.com> Date: Wed, 29 Oct 2025 13:03:35 +0800 Subject: [PATCH] Handle error on response body close to prevent panic --- util/latency.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/util/latency.go b/util/latency.go index dabc08c..ede1b63 100644 --- a/util/latency.go +++ b/util/latency.go @@ -133,7 +133,10 @@ func checkLatency(domain string, ip string, port string) { // 防止后续对 nil Body 的读写导致 panic return } - defer resp.Body.Close() + defer func() { + // 明确忽略关闭时的错误,HTTP 客户端此时已经读完正文 + _ = resp.Body.Close() + }() bodyBytes, err := io.ReadAll(resp.Body) if err != nil {