HttpServer: Make read timeout configurable but disabled by default (#31575) (#32154)

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
(cherry picked from commit 862cd473eb)
This commit is contained in:
Carl Bergquist
2021-03-19 12:01:37 +01:00
committed by GitHub
parent 1df1d60e1e
commit 5039c90b8c
6 changed files with 31 additions and 2 deletions
+4
View File
@@ -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
+4
View File
@@ -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
@@ -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]
@@ -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.
+3 -2
View File
@@ -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:
+5
View File
@@ -205,6 +205,9 @@ type Cfg struct {
RouterLogging bool
Domain string
CDNRootURL *url.URL
ReadTimeout time.Duration
EnableGzip bool
EnforceDomain bool
// build
BuildVersion string
@@ -1361,6 +1364,8 @@ func (cfg *Cfg) readServerSettings(iniFile *ini.File) error {
}
}
cfg.ReadTimeout = server.Key("read_timeout").MustDuration(0)
return nil
}