1
0
mirror of https://github.com/golang/go synced 2024-11-23 00:50:05 -07:00

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 <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
Damien Neil 2023-06-07 14:13:55 -07:00
parent 72b08dbaf3
commit 8bfe839c5f

View File

@ -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",