Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
caddyhttp: New idle_timeout default of 5m
Matthew Holt committed
Nov 18, 2020 at 10:57 UTC
1438e4dbc83353166f30978cf471f05e6c0ecd73
2 files changed
+15
-2
modules/caddyhttp/app.go
+13
@@ -250,6 +250,13 @@ func (app *App) Provision(ctx caddy.Context) error {
250
if err != nil {
251
return fmt.Errorf("server %s: setting up TLS connection policies: %v", srvName, err)
252
}
253
+
254
+ // if there is no idle timeout, set a sane default; users have complained
255
+ // before that aggressive CDNs leave connections open until the server
256
+ // closes them, so if we don't close them it leads to resource exhaustion
257
+ if srv.IdleTimeout == 0 {
258
+ srv.IdleTimeout = defaultIdleTimeout
259
+ }
260
}
261
262
return nil
@@ -458,6 +465,12 @@ func (app *App) httpsPort() int {
465
return app.HTTPSPort
466
}
467
468
+// defaultIdleTimeout is the default HTTP server timeout
469
+// for closing idle connections; useful to avoid resource
470
+// exhaustion behind hungry CDNs, for example (we've had
471
+// several complaints without this).
472
+const defaultIdleTimeout = caddy.Duration(5 * time.Minute)
473
+
474
// Interface guards
475
var (
476
_ caddy.App = (*App)(nil)
modules/caddyhttp/server.go
+2
-2
@@ -59,8 +59,8 @@ type Server struct {
59
WriteTimeout caddy.Duration `json:"write_timeout,omitempty"`
60
61
// IdleTimeout is the maximum time to wait for the next request
62
- // when keep-alives are enabled. If zero, ReadTimeout is used.
63
- // If both are zero, there is no timeout.
62
+ // when keep-alives are enabled. If zero, a default timeout of
63
+ // 5m is applied to help avoid resource exhaustion.
64
IdleTimeout caddy.Duration `json:"idle_timeout,omitempty"`
65
66
// MaxHeaderBytes is the maximum size to parse from a client's