Skip to content

Commit

Permalink
caddyhttp: New idle_timeout default of 5m
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt authored and gilbsgilbs committed Nov 18, 2020
1 parent d094164 commit 3bf0731
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions modules/caddyhttp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ func (app *App) Provision(ctx caddy.Context) error {
if err != nil {
return fmt.Errorf("server %s: setting up TLS connection policies: %v", srvName, err)
}

// if there is no idle timeout, set a sane default; users have complained
// before that aggressive CDNs leave connections open until the server
// closes them, so if we don't close them it leads to resource exhaustion
if srv.IdleTimeout == 0 {
srv.IdleTimeout = defaultIdleTimeout
}
}

return nil
Expand Down Expand Up @@ -458,6 +465,12 @@ func (app *App) httpsPort() int {
return app.HTTPSPort
}

// defaultIdleTimeout is the default HTTP server timeout
// for closing idle connections; useful to avoid resource
// exhaustion behind hungry CDNs, for example (we've had
// several complaints without this).
const defaultIdleTimeout = caddy.Duration(5 * time.Minute)

// Interface guards
var (
_ caddy.App = (*App)(nil)
Expand Down
4 changes: 2 additions & 2 deletions modules/caddyhttp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ type Server struct {
WriteTimeout caddy.Duration `json:"write_timeout,omitempty"`

// IdleTimeout is the maximum time to wait for the next request
// when keep-alives are enabled. If zero, ReadTimeout is used.
// If both are zero, there is no timeout.
// when keep-alives are enabled. If zero, a default timeout of
// 5m is applied to help avoid resource exhaustion.
IdleTimeout caddy.Duration `json:"idle_timeout,omitempty"`

// MaxHeaderBytes is the maximum size to parse from a client's
Expand Down

0 comments on commit 3bf0731

Please sign in to comment.