Skip to content

Commit

Permalink
feat: configurable request read timeouts (#1663)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
TheoTechnicguy authored Dec 23, 2024
1 parent 9326457 commit 0d00311
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 4 additions & 0 deletions docs/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
4 changes: 2 additions & 2 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down

0 comments on commit 0d00311

Please sign in to comment.