From bd76ad0ff1d1bb81cb77cb3417968d3b496380b4 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 15 Apr 2019 21:43:28 -0700 Subject: [PATCH] Revert "Revert "volume: close request body if any parsing error"" This reverts commit 359b7c16507136c927a0ca42d1ade33d142fdc44. --- weed/storage/needle_parse_multipart.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/weed/storage/needle_parse_multipart.go b/weed/storage/needle_parse_multipart.go index 3dba81fcf..93b4c2dce 100644 --- a/weed/storage/needle_parse_multipart.go +++ b/weed/storage/needle_parse_multipart.go @@ -3,6 +3,7 @@ package storage import ( "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/operation" + "io" "io/ioutil" "mime" "net/http" @@ -13,6 +14,12 @@ import ( func parseMultipart(r *http.Request) ( fileName string, data []byte, mimeType string, isGzipped bool, originalDataSize int, isChunkedFile bool, e error) { + defer func() { + if e != nil && r.Body != nil { + io.Copy(ioutil.Discard, r.Body) + r.Body.Close() + } + }() form, fe := r.MultipartReader() if fe != nil { glog.V(0).Infoln("MultipartReader [ERROR]", fe)