S3: add a timeout for single part uploads

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2022-02-01 12:15:56 +01:00
parent d51adb041e
commit cd35636939
10 changed files with 68 additions and 13 deletions

View File

@@ -253,6 +253,7 @@ func (f *Filesystem) GetACopy() Filesystem {
DownloadPartSize: f.S3Config.DownloadPartSize,
DownloadConcurrency: f.S3Config.DownloadConcurrency,
DownloadPartMaxTime: f.S3Config.DownloadPartMaxTime,
UploadPartMaxTime: f.S3Config.UploadPartMaxTime,
ForcePathStyle: f.S3Config.ForcePathStyle,
},
AccessSecret: f.S3Config.AccessSecret.Clone(),

View File

@@ -232,6 +232,17 @@ func (fs *S3Fs) Create(name string, flag int) (File, *PipeWriter, func(), error)
p := NewPipeWriter(w)
ctx, cancelFn := context.WithCancel(context.Background())
uploader := s3manager.NewUploaderWithClient(fs.svc)
if fs.config.UploadPartMaxTime > 0 {
uploader.RequestOptions = append(uploader.RequestOptions, func(r *request.Request) {
chunkCtx, cancel := context.WithTimeout(r.Context(), time.Duration(fs.config.UploadPartMaxTime)*time.Second)
r.SetContext(chunkCtx)
go func() {
<-ctx.Done()
cancel()
}()
})
}
go func() {
defer cancelFn()
key := name

View File

@@ -198,6 +198,9 @@ func (c *S3FsConfig) isEqual(other *S3FsConfig) bool {
if c.DownloadPartMaxTime != other.DownloadPartMaxTime {
return false
}
if c.UploadPartMaxTime != other.UploadPartMaxTime {
return false
}
if c.ForcePathStyle != other.ForcePathStyle {
return false
}