From a366c5c0b13c04a9dae74da28580684c5077a797 Mon Sep 17 00:00:00 2001 From: Theo Technicguy <19630890+TheoTechnicguy@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:05:54 +0100 Subject: [PATCH 1/4] 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 --- config/config.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 8890b996e..459caac50 100644 --- a/config/config.go +++ b/config/config.go @@ -405,9 +405,10 @@ func recoverToError(do func(context.Context) error, onPanic func(any) error) fun } type Downloader struct { - Timeout Duration `yaml:"timeout" default:"5s"` - Attempts uint `yaml:"attempts" default:"3"` - Cooldown Duration `yaml:"cooldown" default:"500ms"` + Timeout Duration `yaml:"timeout" default:"5s"` + ReadTimeout Duration `yaml:"readTimeout" default:"20s"` + Attempts uint `yaml:"attempts" default:"3"` + Cooldown Duration `yaml:"cooldown" default:"500ms"` } func (c *Downloader) LogConfig(logger *logrus.Entry) { From 5c40adccd0cde8954c8cdfc0eac4c7b536fa21bd Mon Sep 17 00:00:00 2001 From: Theo Technicguy <19630890+TheoTechnicguy@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:10:37 +0100 Subject: [PATCH 2/4] feat(server): get read timeout from config --- server/http.go | 10 +++++++--- server/server.go | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/server/http.go b/server/http.go index cac0e8102..1fde8e8f5 100644 --- a/server/http.go +++ b/server/http.go @@ -6,6 +6,7 @@ import ( "net/http" "time" + "github.com/0xERR0R/blocky/config" "github.com/go-chi/chi/v5" "github.com/go-chi/cors" ) @@ -16,16 +17,19 @@ type httpServer struct { name string } -func newHTTPServer(name string, handler http.Handler) *httpServer { +func newHTTPServer(name string, handler http.Handler, cfg *config.Config) *httpServer { const ( readHeaderTimeout = 20 * time.Second - readTimeout = 20 * time.Second writeTimeout = 20 * time.Second ) + var ( + readTimeout = cfg.Blocking.Loading.Downloads.ReadTimeout + ) + return &httpServer{ inner: http.Server{ - ReadTimeout: readTimeout, + ReadTimeout: time.Duration(readTimeout), ReadHeaderTimeout: readHeaderTimeout, WriteTimeout: writeTimeout, diff --git a/server/server.go b/server/server.go index 7404541ad..97ef17988 100644 --- a/server/server.go +++ b/server/server.go @@ -162,7 +162,7 @@ func NewServer(ctx context.Context, cfg *config.Config) (server *Server, err err server.registerDoHEndpoints(httpRouter) if len(cfg.Ports.HTTP) != 0 { - srv := newHTTPServer("http", httpRouter) + srv := newHTTPServer("http", httpRouter, cfg) for _, l := range httpListeners { server.servers[l] = srv @@ -170,7 +170,7 @@ func NewServer(ctx context.Context, cfg *config.Config) (server *Server, err err } if len(cfg.Ports.HTTPS) != 0 { - srv := newHTTPServer("https", httpRouter) + srv := newHTTPServer("https", httpRouter, cfg) for _, l := range httpsListeners { server.servers[l] = srv From 62399c578b742902006633235f237db82274416d Mon Sep 17 00:00:00 2001 From: Theo Technicguy <19630890+TheoTechnicguy@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:11:58 +0100 Subject: [PATCH 3/4] feat(docs): document additional config parameter --- docs/config.yml | 4 ++++ docs/configuration.md | 11 ++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/config.yml b/docs/config.yml index 3e7b4b58e..5c773b2f6 100644 --- a/docs/config.yml +++ b/docs/config.yml @@ -120,6 +120,10 @@ blocking: # optional: timeout for list download (each url). Use large values for big lists or slow internet connections # default: 5s timeout: 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 b7862af83..befd500ba 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -884,11 +884,12 @@ A value of zero or less will disable this feature. Configures how HTTP(S) sources are downloaded: -| Parameter | Type | Mandatory | Default value | Description | -| --------- | -------- | --------- | ------------- | ---------------------------------------------- | -| timeout | duration | no | 5s | Download attempt timeout | -| attempts | int | no | 3 | How many download attempts should be performed | -| cooldown | duration | no | 500ms | Time between the download attempts | +| Parameter | Type | Mandatory | Default value | Description | +| ----------- | -------- | --------- | ------------- | ---------------------------------------------- | +| timeout | duration | no | 5s | Download 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 | !!! example From 231e3ce913edd8f8031a28401018b0ef67395573 Mon Sep 17 00:00:00 2001 From: Theo Technicguy <19630890+TheoTechnicguy@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:49:49 +0100 Subject: [PATCH 4/4] refactor(server): remove superfluous spaces --- server/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/http.go b/server/http.go index 1fde8e8f5..bc04c432c 100644 --- a/server/http.go +++ b/server/http.go @@ -24,7 +24,7 @@ func newHTTPServer(name string, handler http.Handler, cfg *config.Config) *httpS ) var ( - readTimeout = cfg.Blocking.Loading.Downloads.ReadTimeout + readTimeout = cfg.Blocking.Loading.Downloads.ReadTimeout ) return &httpServer{