Repository navigation
network: bound half-closed haproxy sessions on the virtual router - #6
Merged
Merged
Conversation
timeout client and timeout server are the only session timeouts the configurator emits, and network.loadbalancer.haproxy.idle.timeout=0 removes both. Deployments need that zero when long-lived connections must survive an idle period - a Postgres backend reached through a TCP load balancer rule, for instance - so the timeouts cannot simply be put back. With no timeout at all a client that half-closes leaves its session held forever. haproxy keeps the fd, so the socket stays in FIN_WAIT2 or CLOSE_WAIT and the kernel cannot reap it under tcp_fin_timeout, which only applies to orphaned sockets. Enough of them reach maxconn, a per-process budget shared by every VIP the router serves, and the router then completes TCP handshakes from the backlog for connections it never services. Every service behind that router stops answering at once while its backends stay healthy. client-fin and server-fin arm only once a FIN has been seen, so they bound the half-closed case and leave fully open idle connections untouched. Appended rather than inserted: the defaults list is fixed size and indices 7, 9 and 10 are addressed positionally further down the method. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
network.loadbalancer.haproxy.idle.timeout=0blanks bothtimeout clientandtimeout server(see theidleTimeout == 0branch). That zero is deliberate where long-lived connections must not be cut — a Postgres backend behind a TCP LB rule, for example — so the timeouts can't simply be restored.With no session timeout at all, a client that half-closes leaves its session held indefinitely. haproxy keeps the fd, so the socket sits in
FIN_WAIT2/CLOSE_WAITand the kernel can't reap it:tcp_fin_timeoutonly applies to orphaned sockets, and these aren't.Enough of them reach
maxconn, which is a per-process budget shared by every VIP the router serves. Past that, the kernel still completes handshakes from the backlog for sessions haproxy never services — TCP connects, TLS never starts — and every service behind that router stops answering at once while its backends remain healthy.Observed
A production VR reached 4096/4096 with ~4,100 half-closed sessions from a single client:
Two unrelated applications in separate namespaces went down together, for ~25 minutes, until haproxy was restarted. Backend health checks stayed
UPthroughout, because the backends were fine.Fix
timeout client-fin/timeout server-finarm only after a FIN has been seen, so they bound the half-closed case while leaving fully open idle connections untouched. That keeps theidle.timeout=0use case working.Appended rather than inserted: the defaults list is fixed-size and indices 7, 9 and 10 are addressed positionally later in the method.
Testing
timeout client-fin 30svalidates cleanly against the haproxy shipped in the systemvm (2.6.12):🤖 Generated with Claude Code