mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 08:22:24 +01:00
fix (ls): configurable ls timeout for plugins
This commit is contained in:
parent
cea8a77cd8
commit
fa9f1bc3e4
2 changed files with 33 additions and 0 deletions
26
server/plugin/plg_backend_s3/config.go
Normal file
26
server/plugin/plg_backend_s3/config.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package plg_backend_s3
|
||||
|
||||
import (
|
||||
. "github.com/mickael-kerjean/filestash/server/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ls_timeout func() time.Duration
|
||||
|
||||
func init() {
|
||||
ls_timeout = func() time.Duration {
|
||||
return time.Duration(Config.Get("features.protection.ls_timeout").Schema(func(f *FormElement) *FormElement {
|
||||
if f == nil {
|
||||
f = &FormElement{}
|
||||
}
|
||||
f.Default = 2
|
||||
f.Name = "ls_timeout"
|
||||
f.Type = "number"
|
||||
f.Target = []string{}
|
||||
f.Description = "failsafe timeout for listing files under a folder"
|
||||
f.Placeholder = "Default: 2"
|
||||
return f
|
||||
}).Int()) * time.Second
|
||||
}
|
||||
ls_timeout()
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var S3Cache AppCache
|
||||
|
|
@ -169,6 +170,7 @@ func (s S3Backend) Ls(path string) (files []os.FileInfo, err error) {
|
|||
}
|
||||
client := s3.New(s.createSession(p.bucket))
|
||||
|
||||
startTime := time.Now()
|
||||
err = client.ListObjectsV2PagesWithContext(
|
||||
s.context,
|
||||
&s3.ListObjectsV2Input{
|
||||
|
|
@ -194,6 +196,11 @@ func (s S3Backend) Ls(path string) (files []os.FileInfo, err error) {
|
|||
FType: "directory",
|
||||
})
|
||||
}
|
||||
|
||||
if time.Since(startTime) > ls_timeout() {
|
||||
Log.Debug("plg_backend_s3::ls timeout triggered after getting %d files", len(files))
|
||||
return false
|
||||
}
|
||||
return aws.BoolValue(objs.IsTruncated)
|
||||
})
|
||||
return files, err
|
||||
|
|
|
|||
Loading…
Reference in a new issue