diff --git a/pkg/fileservice/aliyun_sdk.go b/pkg/fileservice/aliyun_sdk.go index 8114e59ada640..f1389b421c0f6 100644 --- a/pkg/fileservice/aliyun_sdk.go +++ b/pkg/fileservice/aliyun_sdk.go @@ -498,7 +498,14 @@ func (a *AliyunSDK) getObject(ctx context.Context, key string, min *int64, max * if err != nil { return nil, err } - return r, nil + return &readCloser{ + r: r, + closeFunc: func() error { + // drain + io.Copy(io.Discard, r) + return r.Close() + }, + }, nil }, *min, IsRetryableError, diff --git a/pkg/fileservice/aws_sdk_v2.go b/pkg/fileservice/aws_sdk_v2.go index e25061deb0e27..413a794c0f47a 100644 --- a/pkg/fileservice/aws_sdk_v2.go +++ b/pkg/fileservice/aws_sdk_v2.go @@ -650,7 +650,14 @@ func (a *AwsSDKv2) getObject(ctx context.Context, min *int64, max *int64, params if err != nil { return nil, err } - return output.Body, nil + return &readCloser{ + r: output.Body, + closeFunc: func() error { + // drain + io.Copy(io.Discard, output.Body) + return output.Body.Close() + }, + }, nil }, *min, IsRetryableError, diff --git a/pkg/fileservice/minio_sdk.go b/pkg/fileservice/minio_sdk.go index ff00f486d4347..9d53d13b27424 100644 --- a/pkg/fileservice/minio_sdk.go +++ b/pkg/fileservice/minio_sdk.go @@ -568,7 +568,14 @@ func (a *MinioSDK) getObject(ctx context.Context, key string, min *int64, max *i return nil, err } } - return obj, nil + return &readCloser{ + r: obj, + closeFunc: func() error { + // drain + io.Copy(io.Discard, obj) + return obj.Close() + }, + }, nil }, *min, IsRetryableError, diff --git a/pkg/fileservice/qcloud_sdk.go b/pkg/fileservice/qcloud_sdk.go index 9a5a8e03b5c39..008806f8b609a 100644 --- a/pkg/fileservice/qcloud_sdk.go +++ b/pkg/fileservice/qcloud_sdk.go @@ -484,7 +484,14 @@ func (a *QCloudSDK) getObject(ctx context.Context, key string, min *int64, max * if err != nil { return nil, err } - return resp.Body, nil + return &readCloser{ + r: resp.Body, + closeFunc: func() error { + // drain + io.Copy(io.Discard, resp.Body) + return resp.Body.Close() + }, + }, nil }, maxRetryAttemps, IsRetryableError,