fix: need the reader to be created and closed inside the task

This commit is contained in:
Derrick Hammer 2024-02-01 19:02:24 -05:00
parent 9330bb36bf
commit d15ec4e81e
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 3 deletions

View File

@ -167,14 +167,25 @@ func (r *RenterDefault) MultipartUpload(params MultiPartUploadParams) error {
if end > size { if end > size {
end = size end = size
} }
reader, err := rf(uint(start), uint(end))
next := make(chan struct{}, 0) next := make(chan struct{}, 0)
defer close(next) defer close(next)
job := r.cron.RetryableTask(cron.RetryableTaskParams{ job := r.cron.RetryableTask(cron.RetryableTaskParams{
Name: fileName + "-part-" + strconv.FormatUint(i, 10), Name: fileName + "-part-" + strconv.FormatUint(i, 10),
Function: func() error { Function: func() error {
_, err := r.workerClient.UploadMultipartUploadPart(context.Background(), reader, bucket, fileName, upload.UploadID, int(i), api.UploadMultipartUploadPartOptions{}) reader, err := rf(uint(start), uint(end))
defer func(reader io.ReadCloser) {
err := reader.Close()
if err != nil {
r.logger.Error("failed to close reader", zap.Error(err))
}
}(reader)
if err != nil {
return err
}
_, err = r.workerClient.UploadMultipartUploadPart(context.Background(), reader, bucket, fileName, upload.UploadID, int(i), api.UploadMultipartUploadPartOptions{})
if err != nil { if err != nil {
return err return err
} }