HAProxy maxconn reached: new connections queued and rejected
HAProxy is refusing work. Clients see connection timeouts or resets, load tests fail at a suspiciously round concurrency number, and yet the HAProxy process looks healthy: CPU is fine, memory is fine, the process is up, health checks pass. The stats tell the real story: CurrConns is flat at Maxconn, or scur is pinned at slim on a frontend, and it does not move.
The global or per-frontend maxconn limit has been reached, so HAProxy stops accepting new connections. Those connections pile up in the kernel’s listen backlog, and once the backlog fills, SYNs are dropped silently. From HAProxy’s perspective nothing is wrong, because the connections never reached user space. From the client’s perspective the service is down.
The dangerous property of this failure is that it is a cliff edge, not gradual degradation. HAProxy can serve existing connections at full speed with a healthy Idle_pct while refusing every new connection. If your dashboards only show CPU, request rate, and backend 5xx, this failure is invisible until the tickets arrive.
What this means
HAProxy enforces connection limits at four independent levels: global, frontend, backend, and per-server. When the global or frontend limit is hit, new connections cannot be accepted. They wait in the kernel accept queue (sized by net.core.somaxconn and the SYN backlog). When that queue overflows, the kernel drops SYNs silently. HAProxy never sees them, so no HAProxy error counter increments for the dropped attempts.
flowchart LR client[New client connections] --> backlog[Kernel listen backlog] backlog -->|accept| haproxy[HAProxy event loop] haproxy -->|CurrConns below Maxconn| sessions[Active sessions] haproxy -.->|CurrConns == Maxconn: stop accepting| backlog backlog -.->|backlog full| drop[SYNs dropped silently] drop -.->|client sees| timeout[Connection timeout]
Two things follow. First, the rejection is invisible in HAProxy’s own metrics unless you know where to look (ConnRate vs SessRate gap, kernel ListenOverflows). Second, the fix depends entirely on why the slots are occupied: genuine traffic surge, idle connections holding slots, or a limit set too low for the workload.
Common causes
| Cause | What it looks like | First thing to check |
|---|---|---|
| Genuine traffic surge | scur high AND req_rate high, Idle_pct dropping | Compare rate and req_rate against baseline |
| Idle-connection pile-up | scur high, req_rate low, bin/bout low, qcur zero | show sess to see what connections are holding slots |
| maxconn set too low | Saturation at a round number well below tested capacity | show info Maxconn, and what you actually configured |
| Long-lived connections (WebSocket, SSE, streaming) | scur climbs and never releases, ttime very high | show sess for connection age and state |
| Slow backends holding slots | rtime and ttime rising, connections linger | Per-server rtime, backend dependency health |
| Keep-alive timeout too long | Many idle keep-alive sessions between bursts | timeout http-keep-alive value |
| Reload storm inflating counts | Multiple HAProxy PIDs, old processes holding FDs | pgrep -c haproxy, Stopping field |
| FD limit, not maxconn | Maxsock close to Ulimit-n, accept failures | /proc/<pid>/fd count vs /proc/<pid>/limits |
Quick checks
All read-only. Assumes the runtime socket is at /var/run/haproxy.sock; adjust if your config puts it elsewhere.
# 1. Global saturation: is CurrConns pinned at Maxconn?
echo "show info" | socat unix-connect:/var/run/haproxy.sock stdio | \
grep -E "^(CurrConns|Maxconn|Maxsock|Ulimit-n|ConnRate|SessRate|Idle_pct|Stopping):"
# 2. Per-proxy saturation: which frontend/backend/server is at its limit?
echo "show stat" | socat unix-connect:/var/run/haproxy.sock stdio | \
awk -F, '{if($7>0) print $1"/"$2": scur="$5" slim="$7" pct="int($5/$7*100)"%"}'
# 3. Surge or idle pile-up? Session rate and request rate per frontend.
echo "show stat" | socat unix-connect:/var/run/haproxy.sock stdio | \
awk -F, '$2 == "FRONTEND" {print $1": rate="$34" req_rate="$47}'
# 4. Are connections queueing behind backend/server limits?
echo "show stat" | socat unix-connect:/var/run/haproxy.sock stdio | \
awk -F, '$2 != "FRONTEND" {print $1"/"$2": qcur="$3" qmax="$4}'
# 5. Kernel accept queue overflowing (connections dropped before HAProxy sees them)?
nstat -az | grep -i listen
ss -tln | grep -E ":(80|443) "
# 6. Who is holding the slots?
echo "show sess" | socat unix-connect:/var/run/haproxy.sock stdio | head -50
# 7. FD headroom on the process itself
HPID=$(pgrep -x haproxy | head -1)
echo "FDs used: $(ls /proc/$HPID/fd 2>/dev/null | wc -l)"
grep "Max open files" /proc/$HPID/limits
How to diagnose it
Confirm the cliff. If
CurrConnsis flat atMaxconn(or a frontendscuris flat atslim) and does not fluctuate, you are at the limit. A flat line at exactly the configured number is the signature. If nothing is at a limit, this is not a maxconn problem; look elsewhere.Identify which level is throttling. Check all four: global (
CurrConns/Maxconninshow info), frontend, backend, and per-server (scur/slimper row in the CSV). A per-server limit can bottleneck traffic while the global limit has plenty of headroom, and per-server exhaustion shows up asqcurgrowth rather than accept stalls.Separate surge from pile-up. This decides the fix:
- High
scur+ highreq_rate: genuine load. HAProxy is doing real work for every connection. You need more capacity or a higher limit. - High
scur+ lowreq_rate+ lowbin/bout+qcurzero: connections are open but not carrying traffic. Idle keep-alives, long-lived streams, a client-side connection leak, or a Slowloris-style pattern. Raising maxconn only buys time.
- High
Inspect the sessions.
show sessshows what is holding slots: source IPs, connection age, state. A pile-up dominated by one or a few source IPs is a misbehaving client or an attack. A pile-up of aged connections in an idle state points at keep-alive timeouts.Check for the invisible drops.
ListenOverflows/ListenDropsincrementing innstat -azmeans the kernel backlog is overflowing and SYNs are being dropped before HAProxy can count them. These are system-wide counters, so other listeners contribute, but a rising counter correlated with your incident window is strong evidence.Quantify the rejection rate. The gap between
ConnRateandSessRateinshow infoapproximates how many arriving connections never become sessions. In healthy operation the ratio is close to 1.0.Rule out FD exhaustion as the real ceiling. If
Maxsock(HAProxy’s computed FD ceiling) is close toUlimit-n, the practical limit is file descriptors, not the configured maxconn. Each proxied connection needs roughly two FDs (client side plus server side) plus listeners, stats, log sockets, and health checks. Check/proc/<pid>/fdagainst/proc/<pid>/limitsdirectly.Rule out a reload storm.
pgrep -c haproxyshould show 1-2 processes (3 in master-worker during a reload). Many PIDs means old processes are draining and still holding connections and FDs, shrinking effective capacity. CheckStopping: 1and whetherhard-stop-afteris configured.
Metrics and signals to monitor
| Signal | Why it matters | Warning sign |
|---|---|---|
CurrConns / Maxconn (show info) | Global saturation ratio | Ratio > 80%, or CurrConns flat at Maxconn |
scur / slim per frontend/backend/server | Per-level throttling, independent of global | scur > 90% of slim on any row |
ConnRate vs SessRate (show info) | Gap approximates pre-session rejection rate | Ratio of SessRate/ConnRate well below 1.0 |
rate vs req_rate per frontend | Distinguishes real load from idle pile-up | scur high while req_rate low |
qcur / qmax per backend/server | Requests waiting because server slots are full | Any sustained nonzero qcur |
dcon / dses per frontend | Connections/sessions denied at TCP level | Unexpected increments |
ListenOverflows / ListenDrops (kernel) | SYNs dropped before reaching HAProxy | Counters accelerating |
Idle_pct (show info) | Confirms the bottleneck is admission, not CPU | Healthy Idle_pct while connections are refused |
smax per frontend | Historical peak vs limit, headroom evidence | smax near slim |
rtime / ttime per backend | Slow responses hold slots longer | Rising trend feeding connection pile-up |
Note on Idle_pct: if busy-polling is enabled, Idle_pct sits near zero by design and tells you nothing. Use show activity run-queue depth or system CPU instead.
Fixes
If it is an idle-connection pile-up
Lower keep-alive and client timeouts. Reducing timeout http-keep-alive frees idle keep-alive slots sooner. timeout http-request and timeout client bound how long a connection can sit without completing a request, which is also the primary Slowloris mitigation. Tradeoff: aggressive timeouts can cut off legitimate slow clients on mobile networks or long-polling endpoints.
Identify and constrain the offenders. If show sess shows slot consumption concentrated in a few source IPs, use a stick table to rate-limit connections per source IP. Tradeoff: NAT gateways and corporate proxies legitimately aggregate many users behind one IP.
Fix the client. A client-side connection leak (new connection per request, never closed, or a broken retry loop) will defeat any limit you set. If one client or one user-agent dominates show sess, that is your root cause.
If it is a genuine surge
Scale or shed load. More HAProxy capacity, or reject cheaper at the edge. Raising maxconn alone does not create CPU or backend capacity; if backends are already the constraint, you are just moving the queue.
If maxconn is simply set too low
Raise maxconn with the matching resources. This is not a one-line change:
- File descriptors must follow. Each proxied connection consumes roughly two FDs plus overhead for listeners, stats, logs, and health checks. The process
ulimit -n(or the service manager’sLimitNOFILE) must covermaxconn * 2 + overheadwith at least 20% headroom. If HAProxy computed its own maxconn from the FD limit at startup, raising maxconn in the config without raising the FD limit will fail or be capped. - Memory must follow. Budget roughly 32KB per connection for buffers (two times
tune.bufsize, default 16KB) plus around 20KB of per-connection metadata. 100k connections is on the order of 3-5GB before stick tables, SSL cache, and certificates. - Reload, do not restart. A restart drops all existing connections. Use a reload (SIGUSR2 /
systemctl reload) so the old process drains.
If the kernel backlog is the visible symptom
Raising net.core.somaxconn and the SYN backlog lets the kernel absorb bursts, but it only deepens the waiting room. If HAProxy is at maxconn, deeper backlogs mean clients wait longer before timing out instead of getting a fast refusal. Treat backlog tuning as burst absorption, not as the fix.
If a reload storm is shrinking capacity
Reduce reload frequency (batch config changes), make sure hard-stop-after is set so draining processes cannot linger on long-lived connections indefinitely, and count HAProxy PIDs as a monitored signal.
Prevention
- Alert on the ratio, not the number.
scur/slimandCurrConns/Maxconnas percentages at every level: global, frontend, backend, server. Warning at 75-80%, critical at 90%. Absolute thresholds are meaningless across instance sizes. - Track the rejection gap. Alert on
SessRate/ConnRatefalling below baseline and onListenOverflows/ListenDropsaccelerating. These catch the invisible drops that HAProxy’s own error counters miss. - Baseline the
scurvsreq_raterelationship. If you know what normal concurrency looks like per request rate, pile-ups stand out immediately. - Size limits deliberately. Set global, frontend, and per-server maxconn intentionally, with FD and memory headroom documented next to them. An auto-computed or inherited limit you have never looked at is an incident waiting for a traffic spike.
- Set
hard-stop-afterso reloads cannot strand connections and FDs in draining processes. - Watch
smaxtrends. If the historical peak creeps toward the limit over weeks, you have a runway problem you can fix on a schedule instead of at 3 a.m.
How Netdata helps
- Netdata collects HAProxy stats over the runtime socket, so
scur/slimper proxy andCurrConns/Maxconnglobally are graphed continuously. A flat line pinned at the limit is visible at a glance, including which level (global, frontend, backend, server) is throttling. - Plotting session rate against request rate on the same dashboard makes the surge-vs-pile-up distinction immediate: the two curves diverge when connections stop carrying traffic.
- Correlating HAProxy saturation with node-level network stack metrics surfaces
ListenOverflows/ListenDropsrising in the same window, which is how you catch the SYN drops HAProxy itself never counts. - Ratio-based alerts on
scur/slimfire at 80-90% utilization, before clients start timing out, instead of after. - Per-second collection catches short saturation spikes between scrape intervals that longer-interval polling averages away.
qcurandqtimealongsidescur/slimshow whether the limit being hit is admission-side (frontend/global) or server-side, which changes the fix.
Related guides
- HAProxy scur approaching slim: the concurrent-session saturation signal
- HAProxy maxconn hierarchy: global, frontend, backend, and per-server limits
- HAProxy backend queue building (qcur): requests waiting for a free server slot
- HAProxy Slowloris and idle-connection pile-up: high scur, low request rate
- HAProxy monitoring checklist: the signals every production proxy needs
- How HAProxy actually works in production: a mental model for operators
- HAProxy monitoring maturity model: from survival to expert
- HAProxy health check L4TOUT and L4CON: server marked DOWN and unreachable
- HAProxy health check L7STS: server DOWN on the wrong HTTP status
- HAProxy server flapping: rise, fall, and health checks oscillating UP and DOWN
- HAProxy health checks green but the application is broken: when UP does not mean healthy
- HAProxy backend losing servers: active server count and cascade risk






