Skip to content

network: cap the half-closed timeout at the historical 50s - #7

Merged
Kukunin merged 1 commit into
4.22-testingfrom
haproxy-fin-conditional
Nov 14, 2026
Merged

Kukunin merged 1 commit into
4.22-testingfrom
haproxy-fin-conditional

Conversation

@Kukunin

@Kukunin Kukunin commented Nov 14, 2026 •

Copy link
Copy Markdown

Follow-up to #6, which emitted the fin timeouts unconditionally at 30s. The upstream review on apache#14700 caught that this tightens every deployment, and it was right.

Why

Per the haproxy docs, when the fin timeouts are not set, half-closed connections fall back to timeout client / timeout server:

"By default it is not set, so half-closed connections will use the other timeouts (timeout.client or timeout.tunnel)."

So half-closed connections are already bounded wherever idleTimeout > 0, and a flat 30s silently cut that — a zone on the 50000 default went 50s → 30s with no way back.

But the opposite extreme is also wrong. A zone with a 1hr idle timeout currently holds half-closed connections for an hour, which is exactly the FIN_WAIT buildup the directive exists to prevent:

"particularly useful to avoid keeping connections in FIN_WAIT state for too long… particularly common long connections such as RDP or WebSocket."

What changed

The value is derived rather than fixed: min(idleTimeout, 50000), with idleTimeout = 0 treated as unbounded and therefore capped.

idleTimeout half-closed bound today after
0 unbounded 50000
3600000 (1hr) 1hr 50000 — capped
50000 (default) 50s 50s — unchanged
1234 1234 1234 — unchanged
< 0 50000 50000 — unchanged

Two rules fall out of that:

  1. Never longer than 50000 — the value hardcoded for every deployment before HAProxy Configuration: network.loadbalancer.haproxy.idle.timeout apache/cloudstack#12586 made the session timeouts configurable. No zone ends up above the bound it had historically.
  2. Never longer than idleTimeout — a half-closed connection should not get more budget than an active one.

Everything at or below 50s is untouched, so most deployments see no change. Only zones above 50s are tightened — the case the docs describe — and zones at 0, which had no bound at all.

Note on the static array

Indices 11 and 12 are written on every path rather than left to the array defaults. Arrays.asList wraps the private static field without copying, so set() writes through and persists for the life of the JVM; a network rendered once would otherwise leak its values into every network rendered afterwards. Assigning both slots unconditionally keeps the output dependent only on the current invocation. The underlying mutation issue is left alone.

Testing

HAProxyConfiguratorTest passes (5 tests, 0 failures), covering all three interesting cases: 0 → 50000, 1234 → 1234, 3600000 → 50000.

To validate once the deb builds: us-central1 runs idleTimeout=0, so it exercises the capped branch and should render timeout client-fin 50000. Regenerate the VR config, confirm the value, restart haproxy, then re-run the socket-persistence check that previously showed 0 of 332 half-closed sockets surviving 75s.

apache#14700 will be updated to this shape once validated.

🤖 Generated with Claude Code

@Kukunin
Kukunin force-pushed the haproxy-fin-conditional branch from f99e001 to ea000f1 Compare November 14, 2026 20:44
@Kukunin Kukunin changed the title network: bound half-closed sessions only where nothing else does network: cap the half-closed timeout at the historical 50s Nov 14, 2026
The fin timeouts were emitted unconditionally at 30s, which tightened every
deployment. haproxy falls back to "timeout client"/"timeout server" for
half-closed connections when the fin timeouts are absent, so a zone on the 50000
default already bounded them at 50s and a 30s floor cut that without asking.

Derive the value instead: min(idleTimeout, 50000), with idleTimeout=0 treated as
unbounded and therefore capped. Two rules fall out of that. A half-closed
connection is never held longer than 50000, the value hardcoded for every
deployment before apache#12586 made the session timeouts configurable. And it never
outlives an active one, because a timeout larger than idleTimeout would leave a
dying connection with more budget than a working one.

Everything at or below 50s is unchanged. Only zones above it are tightened,
which is the case haproxy documents the directive for - FIN_WAIT buildup on long
lived protocols such as RDP or WebSocket - and zones at 0, which had no bound at
all.

Indices 11 and 12 are written on every path rather than left to the array
defaults. Arrays.asList wraps the static field without copying, so a set()
writes through to it and persists for the life of the JVM; assigning both slots
unconditionally keeps the rendered config dependent only on this invocation.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Kukunin
Kukunin force-pushed the haproxy-fin-conditional branch from ea000f1 to 76e5b62 Compare November 14, 2026 20:48
@Kukunin
Kukunin merged commit 6c135bc into 4.22-testing Nov 14, 2026
14 checks passed
@Kukunin
Kukunin deleted the haproxy-fin-conditional branch November 14, 2026 21:13
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.

1 participant