From 8bfe839c5f514ae7a466889d74262c9e7d89742f Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Wed, 7 Jun 2023 14:13:55 -0700 Subject: [PATCH] net/http: close response body in TestRequestBodyLimit Failing to close the response body before returning leaks the in-progress request past the test lifetime. Fixes #60264 Change-Id: Ic327d9f8e02e87ed656324aaa042f833d9ea18ca Reviewed-on: https://go-review.googlesource.com/c/go/+/501309 Run-TryBot: Damien Neil TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills --- src/net/http/serve_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go index b712f92cb7..bb380cf4a5 100644 --- a/src/net/http/serve_test.go +++ b/src/net/http/serve_test.go @@ -3012,7 +3012,10 @@ func testRequestBodyLimit(t *testing.T, mode testMode) { // // But that's okay, since what we're really testing is that // the remote side hung up on us before we wrote too much. - _, _ = cst.c.Do(req) + resp, err := cst.c.Do(req) + if err == nil { + resp.Body.Close() + } if atomic.LoadInt64(nWritten) > limit*100 { t.Errorf("handler restricted the request body to %d bytes, but client managed to write %d",