Add Server option KeepAliveDisable (keepalive_disable)

Signed-off-by: Joshua McBeth <joshua.mcbeth@gmail.com>
This commit is contained in:
Joshua McBeth 2025-10-09 16:41:16 -04:00
parent 5b5538c9e5
commit 278709c5fb
3 changed files with 24 additions and 4 deletions

View file

@ -42,6 +42,7 @@ type serverOptions struct {
ReadHeaderTimeout caddy.Duration
WriteTimeout caddy.Duration
IdleTimeout caddy.Duration
KeepAliveDisable bool
KeepAliveInterval caddy.Duration
KeepAliveIdle caddy.Duration
KeepAliveCount int
@ -145,6 +146,13 @@ func unmarshalCaddyfileServerOptions(d *caddyfile.Dispenser) (any, error) {
return nil, d.Errf("unrecognized timeouts option '%s'", d.Val())
}
}
case "keepalive_disable":
if d.NextArg() {
return nil, d.ArgErr()
}
serverOpts.KeepAliveDisable = true
case "keepalive_interval":
if !d.NextArg() {
return nil, d.ArgErr()
@ -331,6 +339,7 @@ func applyServerOptions(
server.ReadHeaderTimeout = opts.ReadHeaderTimeout
server.WriteTimeout = opts.WriteTimeout
server.IdleTimeout = opts.IdleTimeout
server.KeepAliveDisable = opts.KeepAliveDisable
server.KeepAliveInterval = opts.KeepAliveInterval
server.KeepAliveIdle = opts.KeepAliveIdle
server.KeepAliveCount = opts.KeepAliveCount

View file

@ -536,7 +536,7 @@ func (app *App) Start() error {
// create the listener for this socket
lnAny, err := listenAddr.Listen(app.ctx, portOffset, net.ListenConfig{
KeepAliveConfig: net.KeepAliveConfig{
Enable: srv.KeepAliveInterval >= 0 || srv.KeepAliveIdle >= 0 || srv.KeepAliveCount >= 0,
Enable: !srv.KeepAliveDisable,
Interval: time.Duration(srv.KeepAliveInterval),
Idle: time.Duration(srv.KeepAliveIdle),
Count: srv.KeepAliveCount,

View file

@ -74,18 +74,29 @@ type Server struct {
// 5m is applied to help avoid resource exhaustion.
IdleTimeout caddy.Duration `json:"idle_timeout,omitempty"`
// KeepAliveDsiable disables TCP keepalive packets.
// If set, the other TCP KeepAlive settings have no effect.
// KeepAlive is enabled by default.
KeepAliveDisable bool `json:"keepalive_disable,omitempty"`
// KeepAliveInterval is the interval at which TCP keepalive packets
// are sent to keep the connection alive at the TCP layer when no other
// data is being transmitted. The default is 15s.
// data is being transmitted.
// If zero, the default is 15s.
// If negative, underlying socket value is unchanged.
KeepAliveInterval caddy.Duration `json:"keepalive_interval,omitempty"`
// KeepAliveIdle is the time that the connection must be idle before
// the first TCP keep-alive probe is sent when no other data is being
// transmitted. The default is 15s.
// transmitted.
// If zero, the default is 15s.
// If negative, underlying socket value is unchanged.
KeepAliveIdle caddy.Duration `json:"keepalive_idle,omitempty"`
// KeepAliveCount is the maximum number of TCP keep-alive probes that
// should be sent before dropping a connection. The default is 9.
// should be sent before dropping a connection.
// If zero, the default is 9.
// If negative, underlying socket value is unchanged.
KeepAliveCount int `json:"keepalive_count,omitempty"`
// MaxHeaderBytes is the maximum size to parse from a client's