From abf3a7150baa21711efe77437c69f5d09e2ea9e1 Mon Sep 17 00:00:00 2001 From: naiba Date: Tue, 5 Dec 2023 23:21:56 +0800 Subject: [PATCH] Fix HTTP response body not being closed properly --- main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.go b/main.go index 2df4088..a2fe341 100644 --- a/main.go +++ b/main.go @@ -405,6 +405,10 @@ func handleHttpGetTask(task *pb.Task, result *pb.TaskResult) { } func checkHttpResp(taskUrl string, start time.Time, resp *http.Response, err error, result *pb.TaskResult) { + if err == nil { + defer resp.Body.Close() + _, err = io.Copy(io.Discard, resp.Body) + } if err == nil { // 检查 HTTP Response 状态 result.Delay = float32(time.Since(start).Microseconds()) / 1000.0