From 67df033c7f750d27598f233d1a0107743738c38d Mon Sep 17 00:00:00 2001 From: Cooper Lees Date: Tue, 2 Sep 2014 22:15:21 -0700 Subject: [PATCH] Add configurable HTTP read and write timeouts --- config/config.go | 4 ++++ http/http.go | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index d518899..6aaf703 100644 --- a/config/config.go +++ b/config/config.go @@ -73,6 +73,8 @@ type Config struct { Announce Duration `json:"announce"` MinAnnounce Duration `json:"min_announce"` RequestTimeout Duration `json:"request_timeout"` + HttpReadTimeout Duration `json:"http_read_timeout"` + HttpWriteTimeout Duration `json:"http_write_timeout"` NumWantFallback int `json:"default_num_want"` ClientWhitelistEnabled bool `json:"client_whitelist_enabled"` @@ -101,6 +103,8 @@ var DefaultConfig = Config{ Announce: Duration{30 * time.Minute}, MinAnnounce: Duration{15 * time.Minute}, RequestTimeout: Duration{10 * time.Second}, + HttpReadTimeout: Duration{10 * time.Second}, + HttpWriteTimeout: Duration{10 * time.Second}, NumWantFallback: 50, StatsConfig: StatsConfig{ diff --git a/http/http.go b/http/http.go index bbbbfe2..b0b3dd2 100644 --- a/http/http.go +++ b/http/http.go @@ -118,12 +118,14 @@ func Serve(cfg *config.Config, tkr *tracker.Tracker) { glog.V(0).Info("Starting on ", cfg.Addr) - grace := graceful.Server{ + grace := &graceful.Server{ Timeout: cfg.RequestTimeout.Duration, ConnState: srv.connState, Server: &http.Server{ Addr: cfg.Addr, Handler: newRouter(srv), + ReadTimeout: cfg.HttpReadTimeout.Duration, + WriteTimeout: cfg.HttpWriteTimeout.Duration, }, }