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.

feat: drains http body if buffer is too small

divinerapier4cbb6fa1992f
diff --git a/weed/util/http_util.go b/weed/util/http_util.go
index 025cdee7bd..684b4d247b 100644
--- a/weed/util/http_util.go
+++ b/weed/util/http_util.go
@@ -235,8 +235,16 @@ func ReadUrl(fileUrl string, offset int64, size int, buf []byte, isReadRange boo
if err != nil {
return n, err
}
+ if n == int64(len(buf)) {
+ break
+ }
}
-
+ // drains the response body to avoid memory leak
+ data, err := ioutil.ReadAll(reader)
+ if len(data) != 0 {
+ err = fmt.Errorf("buffer size is too small. remains %d", len(data))
+ }
+ return n, err
}
func ReadUrlAsStream(fileUrl string, offset int64, size int, fn func(data []byte)) (int64, error) {