From 1f3ae8a4fb96ab6b5b731e704e12ea66345da339 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Tue, 4 Apr 2023 15:47:10 +0200 Subject: [PATCH] system service: do not close Body The standard lib states that server handlers don't need to close the body, so let's not do that to avoid any unforeseen side effect. [NO TESTS NEEDED] - existing tests should suffice. Signed-off-by: Valentin Rothberg --- pkg/api/handlers/compat/images_build.go | 1 - pkg/api/handlers/libpod/kube.go | 2 -- 2 files changed, 3 deletions(-) diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index 771cc5fcfa..556cab49fb 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -895,7 +895,6 @@ func extractTarFile(r *http.Request) (string, error) { // Content-Length not used as too many existing API clients didn't honor it _, err = io.Copy(tarBall, r.Body) - r.Body.Close() if err != nil { return "", fmt.Errorf("failed Request: Unable to copy tar file from request body %s", r.RequestURI) } diff --git a/pkg/api/handlers/libpod/kube.go b/pkg/api/handlers/libpod/kube.go index 2abefa5d1d..2f53f82d7e 100644 --- a/pkg/api/handlers/libpod/kube.go +++ b/pkg/api/handlers/libpod/kube.go @@ -108,7 +108,6 @@ func KubePlay(w http.ResponseWriter, r *http.Request) { options.Start = types.NewOptionalBool(query.Start) } report, err := containerEngine.PlayKube(r.Context(), r.Body, options) - _ = r.Body.Close() if err != nil { utils.Error(w, http.StatusInternalServerError, fmt.Errorf("playing YAML file: %w", err)) return @@ -132,7 +131,6 @@ func KubePlayDown(w http.ResponseWriter, r *http.Request) { containerEngine := abi.ContainerEngine{Libpod: runtime} report, err := containerEngine.PlayKubeDown(r.Context(), r.Body, entities.PlayKubeDownOptions{Force: query.Force}) - _ = r.Body.Close() if err != nil { utils.Error(w, http.StatusInternalServerError, fmt.Errorf("tearing down YAML file: %w", err)) return