Add configurable HTTP read and write timeouts
This commit is contained in:
parent
0f0296be1e
commit
67df033c7f
2 changed files with 7 additions and 1 deletions
|
@ -73,6 +73,8 @@ type Config struct {
|
||||||
Announce Duration `json:"announce"`
|
Announce Duration `json:"announce"`
|
||||||
MinAnnounce Duration `json:"min_announce"`
|
MinAnnounce Duration `json:"min_announce"`
|
||||||
RequestTimeout Duration `json:"request_timeout"`
|
RequestTimeout Duration `json:"request_timeout"`
|
||||||
|
HttpReadTimeout Duration `json:"http_read_timeout"`
|
||||||
|
HttpWriteTimeout Duration `json:"http_write_timeout"`
|
||||||
NumWantFallback int `json:"default_num_want"`
|
NumWantFallback int `json:"default_num_want"`
|
||||||
|
|
||||||
ClientWhitelistEnabled bool `json:"client_whitelist_enabled"`
|
ClientWhitelistEnabled bool `json:"client_whitelist_enabled"`
|
||||||
|
@ -101,6 +103,8 @@ var DefaultConfig = Config{
|
||||||
Announce: Duration{30 * time.Minute},
|
Announce: Duration{30 * time.Minute},
|
||||||
MinAnnounce: Duration{15 * time.Minute},
|
MinAnnounce: Duration{15 * time.Minute},
|
||||||
RequestTimeout: Duration{10 * time.Second},
|
RequestTimeout: Duration{10 * time.Second},
|
||||||
|
HttpReadTimeout: Duration{10 * time.Second},
|
||||||
|
HttpWriteTimeout: Duration{10 * time.Second},
|
||||||
NumWantFallback: 50,
|
NumWantFallback: 50,
|
||||||
|
|
||||||
StatsConfig: StatsConfig{
|
StatsConfig: StatsConfig{
|
||||||
|
|
|
@ -118,12 +118,14 @@ func Serve(cfg *config.Config, tkr *tracker.Tracker) {
|
||||||
|
|
||||||
glog.V(0).Info("Starting on ", cfg.Addr)
|
glog.V(0).Info("Starting on ", cfg.Addr)
|
||||||
|
|
||||||
grace := graceful.Server{
|
grace := &graceful.Server{
|
||||||
Timeout: cfg.RequestTimeout.Duration,
|
Timeout: cfg.RequestTimeout.Duration,
|
||||||
ConnState: srv.connState,
|
ConnState: srv.connState,
|
||||||
Server: &http.Server{
|
Server: &http.Server{
|
||||||
Addr: cfg.Addr,
|
Addr: cfg.Addr,
|
||||||
Handler: newRouter(srv),
|
Handler: newRouter(srv),
|
||||||
|
ReadTimeout: cfg.HttpReadTimeout.Duration,
|
||||||
|
WriteTimeout: cfg.HttpWriteTimeout.Duration,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue