mirror of
https://github.com/sot-tech/mochi.git
synced 2026-06-17 09:59:46 -07:00
Add configurable HTTP read and write timeouts
This commit is contained in:
@@ -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{
|
||||
|
||||
+3
-1
@@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user