From dea6cf315e4a76e4efd7158839712c504c5316e1 Mon Sep 17 00:00:00 2001 From: Para Dox Date: Thu, 29 May 2025 01:26:24 +0700 Subject: [PATCH] more features --- benchmark-proxy/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/benchmark-proxy/main.go b/benchmark-proxy/main.go index 0726fabe..dbfa1bd0 100644 --- a/benchmark-proxy/main.go +++ b/benchmark-proxy/main.go @@ -1405,7 +1405,8 @@ func handleRequest(w http.ResponseWriter, r *http.Request, backends []Backend, c } return } - defer resp.Body.Close() + + // Don't close resp.Body here - it will be closed by the winner or drained by losers // Signal primary response immediately for secondary backends to check if b.Role == "primary" && resp.StatusCode < 400 { @@ -1433,6 +1434,7 @@ func handleRequest(w http.ResponseWriter, r *http.Request, backends []Backend, c } else { // Not the winning response, need to drain and close the body io.Copy(io.Discard, resp.Body) + resp.Body.Close() } }(backend) }