mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-06 14:20:55 +03:00
S3: add a timeout for single part uploads
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -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(),
|
||||
|
||||
11
vfs/s3fs.go
11
vfs/s3fs.go
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user