Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

close http response

Chris Lu5f55a87101f7
diff --git a/weed/operation/upload_content.go b/weed/operation/upload_content.go
index c036bce3bd..df86dd173e 100644
--- a/weed/operation/upload_content.go
+++ b/weed/operation/upload_content.go
@@ -225,11 +225,7 @@ func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error
glog.V(1).Infof("failing to upload to %v: %v", uploadUrl, post_err)
return nil, fmt.Errorf("failing to upload to %v: %v", uploadUrl, post_err)
}
- defer resp.Body.Close()
- resp_body, ra_err := ioutil.ReadAll(resp.Body)
- if ra_err != nil {
- return nil, ra_err
- }
+ defer util.CloseResponse(resp)
var ret UploadResult
etag := getEtag(resp)
@@ -238,6 +234,11 @@ func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error
return &ret, nil
}
+ resp_body, ra_err := ioutil.ReadAll(resp.Body)
+ if ra_err != nil {
+ return nil, ra_err
+ }
+
unmarshal_err := json.Unmarshal(resp_body, &ret)
if unmarshal_err != nil {
glog.V(0).Infoln("failing to read upload response", uploadUrl, string(resp_body))
diff --git a/weed/util/http_util.go b/weed/util/http_util.go
index 5159fcd175..7cc64ea854 100644
--- a/weed/util/http_util.go
+++ b/weed/util/http_util.go
@@ -368,6 +368,7 @@ func ReadUrlAsReaderCloser(fileUrl string, rangeHeader string) (io.ReadCloser, e
if err != nil {
return nil, err
}
+ defer CloseResponse(r)
if r.StatusCode >= 400 {
return nil, fmt.Errorf("%s: %s", fileUrl, r.Status)
}