]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: close response body in TestRequestBodyLimit
authorDamien Neil <dneil@google.com>
Wed, 7 Jun 2023 21:13:55 +0000 (14:13 -0700)
committerDamien Neil <dneil@google.com>
Wed, 7 Jun 2023 23:23:37 +0000 (23:23 +0000)
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>
src/net/http/serve_test.go

index b712f92cb7148c55dade134d9bdf94b8d4ac0190..bb380cf4a5378d01d6c915b7f2930388e3e79b39 100644 (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",