HAProxy connection reuse dropping: http-reuse, pooling, and handshake overhead
Backend latency crept up, CPU on the HAProxy host is climbing, and ctime went from zero to measurable milliseconds, but the backends are healthy and the network looks fine. Before you blame the application or the network, check the one ratio almost nobody graphs: connection reuse, reuse / (connect + reuse) on the backend. If it fell off a cliff, HAProxy stopped reusing pooled backend connections and is now paying a full TCP (and possibly TLS) handshake for every request.
Nothing errors and nothing pages on its own. HAProxy just works harder per request until ephemeral ports or CPU run out, and by then the symptom (latency, econ spikes, TLS CPU saturation) points everywhere except the actual cause.
What this means
HAProxy maintains a pool of idle, previously used backend connections per server. When a request needs a backend connection, HAProxy first tries to pull one from the pool (reuse); only if the pool is empty or the connection is unusable does it open a new one (connect). Both are cumulative counters in the stats CSV, per backend and per server.
The reuse ratio tells you what fraction of backend connection demands were satisfied from the pool:
pool utilization = reuse / (connect + reuse)
A healthy HTTP backend with keep-alive typically sits well above 50%, often much higher. A sudden drop means requests that used to ride pooled connections now each open a fresh socket. The usual trigger is configuration drift on either side: a backend switched HTTP version, disabled keep-alive, or started sending Connection: close, and nothing alerted because nothing technically failed.
The consequences compound:
ctimeappears. With reuse working, connect time is zero for most requests. Nonzeroctimeshowing up on a backend that historically read zero is the fingerprint of broken pooling.SslBackendKeyRatespikes. If backend connections are TLS, every new connection pays a full handshake. Backend TLS handshakes are CPU spent inside HAProxy’s event loop.- Ephemeral port pressure rises. Each new backend connection consumes an ephemeral port on the HAProxy host. With roughly 28K ports in the default local range and a 60s TIME_WAIT, the sustained new-connection rate caps out near 450/s. Past that,
connect()fails and you geteconspikes with no backend-side failure at all. - Latency grows. Each request now includes connect time plus handshake time it did not have before.
flowchart TD A[Backend config drift:
HTTP version change, keep-alive off,
Connection: close header] --> B[Pool starves:
idle_conn_cur falls toward 0] B --> C[reuse ratio drops] C --> D[ctime becomes nonzero] C --> E[SslBackendKeyRate spikes
if backend TLS] C --> F[ephemeral port churn rises] F --> G[econ spikes with no
backend-side failure] D --> H[request latency grows] E --> H G --> H
Common causes
| Cause | What it looks like | First thing to check |
|---|---|---|
Backend started sending Connection: close | Reuse ratio collapses, idle_conn_cur near zero, no HAProxy config change on your side | Response headers from the backend (curl -sv through HAProxy and look at Connection) |
| Backend disabled keep-alive or changed HTTP version | Same signature; often correlates with an app deploy or web server config change | Deploy timeline vs. the moment connect rate diverged from reuse rate |
http-reuse unset or set to never in HAProxy config | Reuse was never high, or dropped after an HAProxy config reload | grep -r "http-reuse" /etc/haproxy/ |
Pool disabled by pool-max-conn 0 or server config change | Idle pool empty even though backend supports keep-alive | Backend and server lines in the config |
| Ephemeral port exhaustion already biting | econ rising, high connect rate, TIME_WAIT pile-up | ss -s or /proc/net/sockstat on the HAProxy host |
| Backend maxconn saturation masking the pool | Reuse looks low because connections are held, not idled | Per-server scur vs slim, qcur |
Quick checks
All read-only. Run against the stats socket.
# Backend-level connect vs reuse counters (CSV fields 82/83, 1-indexed)
echo "show stat" | socat unix-connect:/var/run/haproxy.sock stdio | \
awk -F, '$2 == "BACKEND" {print $1": connect="$82" reuse="$83}'
# Per-server idle and in-use pool gauges
echo "show stat" | socat unix-connect:/var/run/haproxy.sock stdio | \
awk -F, '$2 != "FRONTEND" && $2 != "BACKEND" {print $1"/"$2": idle="$93" safe="$94" used="$95" need_est="$96}'
# Connect time: nonzero on a backend that used to read 0 is the fingerprint
echo "show stat" | socat unix-connect:/var/run/haproxy.sock stdio | \
awk -F, '$2 == "BACKEND" {print $1": ctime="$60"ms qtime="$59"ms rtime="$61"ms"}'
# Backend TLS handshake rate (only relevant if server lines use ssl)
echo "show info" | socat unix-connect:/var/run/haproxy.sock stdio | \
grep -E "^(SslBackendKeyRate|SslFrontendKeyRate|Idle_pct):"
# Connection errors: are new connects failing yet?
echo "show stat" | socat unix-connect:/var/run/haproxy.sock stdio | \
awk -F, '$2 != "FRONTEND" {print $1"/"$2": econ="$14}'
# Ephemeral port and TIME_WAIT pressure on the HAProxy host
ss -s
cat /proc/net/sockstat
# Confirm what the backend actually sends
curl -sv -o /dev/null http://<frontend>/ 2>&1 | grep -i "^< connection"
Field positions are stable in the CSV format but worth confirming against the management documentation for your version before scripting against them.
connect and reuse are cumulative counters that reset on every reload. To compute the ratio you need deltas over an interval, or a monitoring system that handles counter resets.
How to diagnose it
Confirm the drop. Compute
reuse / (connect + reuse)from deltas over two intervals a few minutes apart, per backend. Compare against your historical baseline. A drop from, say, 80% to 10% with steady request rate is the incident.Localize it. Break the counters down per server. If every server in the backend dropped simultaneously, the cause is backend-wide: an application deploy, a shared config change, or an HAProxy-side directive. If only one server dropped, look at that server’s config or version.
Check the timeline against reloads and deploys. A reuse drop exactly at an HAProxy reload points at the HAProxy config (
http-reuse,pool-max-conn, server-line changes). A drop at a backend deploy with no HAProxy reload points at the application: keep-alive disabled, HTTP version change, or a framework/proxy in front of the app now emittingConnection: close.Verify the response headers.
curl -svthrough the frontend and against a backend directly. If the direct response carriesConnection: close, HAProxy is behaving correctly: it cannot pool a connection the server refuses to keep alive. The fix belongs on the backend.Check pool state.
idle_conn_curnear zero while traffic is flowing means connections are never returned to the pool (server closes them) or the pool is disabled.used_conn_curhigh withidle_conn_curnear zero can also mean connections are simply always busy, which is saturation, not broken reuse. Correlate with per-serverscur/slimandqcurbefore concluding pooling is broken.Assess the blast radius. Check
SslBackendKeyRate(if backend TLS),ctime, and host-level TIME_WAIT counts. If TIME_WAIT is climbing toward the ephemeral range ceiling, you are on the clock: when ports run out,econstarts and requests fail.For deeper pool introspection,
show servers conn <backend>on the runtime API shows per-server idle and used connection detail. Use it for live debugging, not for continuous polling.
Metrics and signals to monitor
| Signal | Why it matters | Warning sign |
|---|---|---|
reuse / (connect + reuse) per backend | The reuse ratio itself; the leading indicator of pooling drift | Any sudden drop from baseline |
idle_conn_cur per server | Idle pool depth; zero under load means connections never return | Sustained zero with active traffic |
safe_conn_cur / used_conn_cur per server | Pool composition: proven-reusable vs. in-use connections | Used high, idle and safe pinned at zero |
ctime per backend | Connect cost appearing in request path | Nonzero where it historically read ~0 |
SslBackendKeyRate | Backend TLS handshake CPU cost | Spike correlated with reuse drop |
econ rate | Connect failures, including ephemeral port exhaustion | Rising with no backend-side failure |
| Host TIME_WAIT count | Ephemeral port consumption | Approaching the local port range ceiling |
Idle_pct | Event loop headroom; TLS handshakes burn CPU | Falling as SslBackendKeyRate rises |
Fixes
Backend sends Connection: close or disabled keep-alive
This is the most common root cause and it is not fixable in HAProxy. Fix the backend: re-enable keep-alive in the application server or the intermediary (nginx, ingress, framework server) that started closing connections. Verify with curl -sv that responses no longer carry Connection: close. The reuse ratio recovers on its own once connections can be pooled again.
HAProxy config drifted
Set http-reuse explicitly in the backend or defaults section instead of relying on inheritance. safe reuses idle connections only for requests HAProxy considers safe to replay; aggressive and always reuse progressively more aggressively; never disables reuse entirely. Check that nothing set pool-max-conn 0 (which disables the idle pool) and that no server-line or backend change removed pooling. Reload and watch reuse recover within minutes.
Tradeoff: http-reuse always maximizes reuse but changes semantics around which requests may share a connection, and the default value of http-reuse has changed across major versions. Read the configuration manual for your version before switching from safe.
Ephemeral port exhaustion already in progress
This is triage while you fix the root cause:
- Restoring connection reuse is the real fix. Each reused connection is one fewer port in TIME_WAIT.
- Widening
net.ipv4.ip_local_port_rangeand enablingnet.ipv4.tcp_tw_reusebuys headroom but does not fix churn. These are sysctl changes applied on the live host; test them during a low-traffic window if you are unsure of the impact on your network path. - Watch
econ: if it is already rising, you are at the cliff, and the connect failure ratioecon / (connect + reuse)tells you how far over.
Pool disabled deliberately and load grew
Some deployments disable reuse to work around a backend bug, then forget. If the workaround predates the current team, re-test with reuse enabled on one backend and watch idle_conn_cur, ctime, and eresp. Old backend bugs that motivated http-reuse never are often long fixed.
Prevention
- Graph the reuse ratio per backend. This is the whole lesson. The counters exist in the stats CSV; almost nobody computes the ratio. Alert on a sustained drop from baseline, not an absolute threshold, since healthy ratios vary by workload.
- Alert on nonzero
ctimewhere it used to be zero. Cheap, high-signal proxy for pooling breakdown. - Track
SslBackendKeyRateon any backend that uses TLS. A spike with steady request rate means handshake overhead returned. - Monitor host TIME_WAIT and ephemeral range utilization on HAProxy hosts with high backend churn.
- Treat backend connection semantics as a contract. If your platform ships application deploys that can change keep-alive behaviour or HTTP versions, note it in the deploy checklist. The reuse ratio will catch it, but only if someone is watching.
- Set
http-reuseexplicitly in the config rather than relying on defaults, so a defaults-section edit or version upgrade does not silently change pooling for every backend.
How Netdata helps
- Netdata collects the HAProxy stats CSV fields including
connect,reuse, and the per-server pool gauges, so the reuse ratio andidle_conn_curare graphed per backend and per server without hand-rolled socket polling. - Counter resets on reload are handled automatically, so the ratio computed from cumulative
connect/reusecounters does not produce phantom drops at every config reload. ctime,qtime, andrtimeare charted alongside the pool signals on the same backend, which makes the “reuse dropped, ctime appeared, latency grew” correlation visible in one view instead of three terminals.- Backend TLS handshake rate and
Idle_pctfromshow infosit next to the CSV metrics, so CPU cost from lost reuse is attributable to handshakes rather than guessed at. - Host-level socket and TIME_WAIT metrics from the same agent close the loop on ephemeral port pressure without a separate monitoring stack.
Related guides
- HAProxy connect time (ctime) high: network latency and backend accept-queue overflow
- HAProxy connection errors (econ): backend connections refused, timed out, or reset
- HAProxy 502 Bad Gateway: backend connection and response failures
- HAProxy scur approaching slim: the concurrent-session saturation signal
- HAProxy backend queue building (qcur): requests waiting for a free server slot
- HAProxy 5xx delta: telling HAProxy-generated errors from backend errors






