diff --git a/conf/defaults.ini b/conf/defaults.ini index b274ffbcf0f..801dea28d33 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -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 diff --git a/conf/sample.ini b/conf/sample.ini index 770210fc5b2..4ba183facc1 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -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 diff --git a/docs/sources/administration/configuration.md b/docs/sources/administration/configuration.md index 6920006df9e..41d70177c5b 100644 --- a/docs/sources/administration/configuration.md +++ b/docs/sources/administration/configuration.md @@ -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..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. +
## [database] diff --git a/docs/sources/whatsnew/whats-new-in-v7-5.md b/docs/sources/whatsnew/whats-new-in-v7-5.md index f8eed01d666..df2b9c5d1db 100644 --- a/docs/sources/whatsnew/whats-new-in-v7-5.md +++ b/docs/sources/whatsnew/whats-new-in-v7-5.md @@ -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. diff --git a/pkg/api/http_server.go b/pkg/api/http_server.go index 85e3c232b82..092c90c3e6f 100644 --- a/pkg/api/http_server.go +++ b/pkg/api/http_server.go @@ -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: diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index 10adfd444e3..56661a9b6c7 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -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 }