diff --git a/CHANGELOG.md b/CHANGELOG.md index eeb5499e..d3278947 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to paopao-ce are documented in this file. ## 0.5.0+dev ([`dev`](https://github.com/rocboss/paopao-ce/tree/dev)) +## 0.4.2 +### Fixed +- fixed remove multi-objects no effects and occurs resource leak error when use Minio as OSS(Object Storage System). + ## 0.4.1 ### Changed - infinite scrolling instead of pagination for Home/User/Profile page diff --git a/internal/dao/storage/minio.go b/internal/dao/storage/minio.go index cc2b71a2..028e331a 100644 --- a/internal/dao/storage/minio.go +++ b/internal/dao/storage/minio.go @@ -134,16 +134,15 @@ func (s *minioServant) DeleteObject(objectKey string) error { func (s *minioServant) DeleteObjects(objectKeys []string) (err error) { objectsCh := make(chan minio.ObjectInfo, len(objectKeys)) - go func() { - defer close(objectsCh) - for _, objectKey := range objectKeys { - objectsCh <- minio.ObjectInfo{ - Key: objectKey, - } + resCh := s.client.RemoveObjects(context.Background(), s.bucket, objectsCh, minio.RemoveObjectsOptions{}) + for _, objectKey := range objectKeys { + objectsCh <- minio.ObjectInfo{ + Key: objectKey, } - }() + } + // 记得一定要close,否则会被卡死,退出不了函数,造成资源泄露!!! + close(objectsCh) - resCh := s.client.RemoveObjects(context.Background(), s.bucket, objectsCh, minio.RemoveObjectsOptions{}) // 宽松处理所有错误,只记录最后一次发生的错误 for result := range resCh { if result.Err != nil {