Skip to content

http: disable keepalive when KeepAliveInterval is negative - #7158

Merged
francislavoie merged 2 commits into
masterfrom
http-fix-disable-keepalive
Aug 20, 2025
Merged

francislavoie merged 2 commits into
masterfrom
http-fix-disable-keepalive

Conversation

@WeidiDeng

Copy link
Copy Markdown
Member

In 7151, net.KeepAliveConfig is used instead of KeepAlive. However, this made disabling keep alive impossible, as a negative value of Interval will just left the underlying socket option unchanged.

For now, disable keep alive when KeepAliveInterval is negative, when it's zero, a system dependent default is chosen automatically.

@WeidiDeng
WeidiDeng force-pushed the http-fix-disable-keepalive branch from c45b8a7 to 9e20678 Compare August 6, 2025 02:45
@WeidiDeng

Copy link
Copy Markdown
Member Author

In 7157, whether net.KeepAliveConfig.Enable is true depend on if the ProbeInterval is positive because in that case, we use net.Dialer which willl handle keep alive for us. Namely, if net.KeepAliveConfig.Enable is false and KeepAlive is zero, a default value will be chosen. Though reverse proxy will use 30 seconds if not configured explicitly.

When listening, sometimes we don't use net.ListenConfig to listen, for example, socket activation. So keep alive is enabled by default as well.

@mohammed90 mohammed90 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@francislavoie
francislavoie merged commit fdf6108 into master Aug 20, 2025
@francislavoie
francislavoie deleted the http-fix-disable-keepalive branch August 20, 2025 21:31
@BrewTestBot BrewTestBot mentioned this pull request Aug 22, 2025
1 task done
@francislavoie francislavoie added this to the v2.10.1 milestone Aug 22, 2025
mohammed90 pushed a commit to cedricziel/caddy that referenced this pull request Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants