Skip to content

Commit

Permalink
fileservice: drain response reader to ensure connection reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
reusee committed Dec 17, 2024
1 parent 2c297e3 commit bc03dd8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
9 changes: 8 additions & 1 deletion pkg/fileservice/aliyun_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion pkg/fileservice/aws_sdk_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion pkg/fileservice/minio_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion pkg/fileservice/qcloud_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bc03dd8

Please sign in to comment.