Skip to content

Commit

Permalink
HttpServer: Make read timeout configurable but disabled by default (g…
Browse files Browse the repository at this point in the history
…rafana#31575) (grafana#32154)

Co-authored-by: achatterjee-grafana <[email protected]>
(cherry picked from commit 862cd47)
  • Loading branch information
bergquist authored Mar 19, 2021
1 parent 1df1d60 commit 5039c90
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions conf/defaults.ini
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ socket = /tmp/grafana.sock
# CDN Url
cdn_url =

# Sets the maximum time in minutes before timing out read of an incoming request and closing idle connections.
# `0` means there is no timeout for reading the request.
read_timeout = 0

#################################### Database ############################
[database]
# You can configure the database connection by specifying type, host, name, user and password
Expand Down
4 changes: 4 additions & 0 deletions conf/sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
# CDN Url
;cdn_url =

# Sets the maximum time using a duration format (5s/5m/5ms) before timing out read of an incoming request and closing idle connections.
# `0` means there is no timeout for reading the request.
;read_timeout = 0

#################################### Database ####################################
[database]
# You can configure the database connection by specifying type, host, name, user and password
Expand Down
5 changes: 5 additions & 0 deletions docs/sources/administration/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ Specify a full HTTP URL address to the root of your Grafana CDN assets. Grafana
For example, given a cdn url like `https://cdn.myserver.com` grafana will try to load a javascript file from
`http://cdn.myserver.com/grafana-oss/v7.4.0/public/build/app.<hash>.js`.

### read_timeout

Sets the maximum time using a duration format (5s/5m/5ms) before timing out read of an incoming request and closing idle connections.
`0` means there is no timeout for reading the request.

<hr />

## [database]
Expand Down
10 changes: 10 additions & 0 deletions docs/sources/whatsnew/whats-new-in-v7-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,13 @@ If you enable the feature, then you can use template variables in reports.
## Breaking changes

There are no known breaking changes in this release.

## Updated configuration

```
[server]
read_timeout = 0
```

Sets the maximum time using a duration format (5s/5m/5ms) before timing out read of an incoming request and closing idle connections.
`0` means there is no timeout for reading the request.
5 changes: 3 additions & 2 deletions pkg/api/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ func (hs *HTTPServer) Run(ctx context.Context) error {
// Remove any square brackets enclosing IPv6 addresses, a format we support for backwards compatibility
host := strings.TrimSuffix(strings.TrimPrefix(setting.HttpAddr, "["), "]")
hs.httpSrv = &http.Server{
Addr: net.JoinHostPort(host, setting.HttpPort),
Handler: hs.macaron,
Addr: net.JoinHostPort(host, setting.HttpPort),
Handler: hs.macaron,
ReadTimeout: hs.Cfg.ReadTimeout,
}
switch hs.Cfg.Protocol {
case setting.HTTP2Scheme:
Expand Down
5 changes: 5 additions & 0 deletions pkg/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ type Cfg struct {
RouterLogging bool
Domain string
CDNRootURL *url.URL
ReadTimeout time.Duration
EnableGzip bool
EnforceDomain bool

// build
BuildVersion string
Expand Down Expand Up @@ -1361,6 +1364,8 @@ func (cfg *Cfg) readServerSettings(iniFile *ini.File) error {
}
}

cfg.ReadTimeout = server.Key("read_timeout").MustDuration(0)

return nil
}

Expand Down

0 comments on commit 5039c90

Please sign in to comment.