From e7483b40b34f7c01ad08a69c83b56d9fc79edc01 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 30 May 2022 10:14:37 +0100 Subject: [PATCH] fshttp: add --disable-http-keep-alives to disable HTTP Keep Alives See: https://forum.rclone.org/t/getting-rate-limited-before-advertised-limit-on-s3-compatible-object-storage/31010/ --- fs/config.go | 1 + fs/config/configflags/configflags.go | 1 + fs/fshttp/http.go | 1 + 3 files changed, 3 insertions(+) diff --git a/fs/config.go b/fs/config.go index 5eb85ec61..e96be37d0 100644 --- a/fs/config.go +++ b/fs/config.go @@ -132,6 +132,7 @@ type ConfigInfo struct { DisableHTTP2 bool HumanReadable bool KvLockTime time.Duration // maximum time to keep key-value database locked by process + DisableHTTPKeepAlives bool } // NewConfig creates a new config with everything set to the default diff --git a/fs/config/configflags/configflags.go b/fs/config/configflags/configflags.go index 7c2c8ade9..8e3e8d558 100644 --- a/fs/config/configflags/configflags.go +++ b/fs/config/configflags/configflags.go @@ -137,6 +137,7 @@ func AddFlags(ci *fs.ConfigInfo, flagSet *pflag.FlagSet) { flags.BoolVarP(flagSet, &ci.DisableHTTP2, "disable-http2", "", ci.DisableHTTP2, "Disable HTTP/2 in the global transport") flags.BoolVarP(flagSet, &ci.HumanReadable, "human-readable", "", ci.HumanReadable, "Print numbers in a human-readable format, sizes with suffix Ki|Mi|Gi|Ti|Pi") flags.DurationVarP(flagSet, &ci.KvLockTime, "kv-lock-time", "", ci.KvLockTime, "Maximum time to keep key-value database locked by process") + flags.BoolVarP(flagSet, &ci.DisableHTTPKeepAlives, "disable-http-keep-alives", "", ci.DisableHTTPKeepAlives, "Disable HTTP keep-alives and use each connection once.") } // ParseHeaders converts the strings passed in via the header flags into HTTPOptions diff --git a/fs/fshttp/http.go b/fs/fshttp/http.go index ef7cf2851..9384d2fa4 100644 --- a/fs/fshttp/http.go +++ b/fs/fshttp/http.go @@ -53,6 +53,7 @@ func NewTransportCustom(ctx context.Context, customize func(*http.Transport)) ht t.MaxIdleConns = 2 * t.MaxIdleConnsPerHost t.TLSHandshakeTimeout = ci.ConnectTimeout t.ResponseHeaderTimeout = ci.Timeout + t.DisableKeepAlives = ci.DisableHTTPKeepAlives // TLS Config t.TLSClientConfig = &tls.Config{