From 0d00311513b6f566e19e0721761d3f381526666f Mon Sep 17 00:00:00 2001 From: TheoTechnicguy <19630890+TheoTechnicguy@users.noreply.github.com> Date: Mon, 23 Dec 2024 20:39:50 +0000 Subject: [PATCH] feat: configurable request read timeouts (#1663) * feat(config): read read timeout value This commit adds a request read timeout configuration parameter. As it is part of the downloading cycle, it is available under `blocking/loading/downloads`. The default value comes from `server/http.go` line 22. Refs: #1653 * feat(server): get read timeout from config * feat(docs): document additional config parameter * refactor(server): remove superfluous spaces --- config/config.go | 1 + docs/config.yml | 4 ++++ docs/configuration.md | 1 + server/http.go | 4 ++-- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 81a596fca..e5d1ce647 100644 --- a/config/config.go +++ b/config/config.go @@ -406,6 +406,7 @@ func recoverToError(do func(context.Context) error, onPanic func(any) error) fun type Downloader struct { Timeout Duration `yaml:"timeout" default:"5s"` + ReadTimeout Duration `yaml:"readTimeout" default:"20s"` WriteTimeout Duration `yaml:"writeTimeout" default:"20s"` Attempts uint `yaml:"attempts" default:"3"` Cooldown Duration `yaml:"cooldown" default:"500ms"` diff --git a/docs/config.yml b/docs/config.yml index 745e21e05..4a03ef86d 100644 --- a/docs/config.yml +++ b/docs/config.yml @@ -123,6 +123,10 @@ blocking: # optional: timeout for list write to disk (each url). Use larger values for big lists or in constrained environments # default: 20s writeTimeout: 60s + # optional: timeout for reading the download (each url). Use large values for big lists or in constrained environments + # To disable this timeout, set to 0. + # default: 20s + readTimeout: 60s # optional: Maximum download attempts # default: 3 attempts: 5 diff --git a/docs/configuration.md b/docs/configuration.md index 8c37f574c..9db2d58f6 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -888,6 +888,7 @@ Configures how HTTP(S) sources are downloaded: | ------------ | -------- | --------- | ------------- | ---------------------------------------------- | | timeout | duration | no | 5s | Download attempt timeout | | writeTimeout | duration | no | 20s | File write attempt timeout | +| readTimeout | duration | no | 20s | Download request read timeout | | attempts | int | no | 3 | How many download attempts should be performed | | cooldown | duration | no | 500ms | Time between the download attempts | diff --git a/server/http.go b/server/http.go index 5b06cd154..7019cb21f 100644 --- a/server/http.go +++ b/server/http.go @@ -20,16 +20,16 @@ type httpServer struct { func newHTTPServer(name string, handler http.Handler, cfg *config.Config) *httpServer { const ( readHeaderTimeout = 20 * time.Second - readTimeout = 20 * time.Second ) var ( writeTimeout = cfg.Blocking.Loading.Downloads.WriteTimeout + readTimeout = cfg.Blocking.Loading.Downloads.ReadTimeout ) return &httpServer{ inner: http.Server{ - ReadTimeout: readTimeout, + ReadTimeout: time.Duration(readTimeout), ReadHeaderTimeout: readHeaderTimeout, WriteTimeout: time.Duration(writeTimeout),