maxuru ~ % cat haproxy/timeouts-and-limits
Set HAProxy timeouts and connection limits
/etc/haproxy/haproxy.cfgdefaults timeout http-request 10s timeout connect 5s timeout client 30s timeout server 30s timeout http-keep-alive 10s timeout queue 30s
global maxconn 20000Why this is rated low
Section titled “Why this is rated low”Because it is availability, not compromise. Nothing here stops an intrusion or protects data — a proxy that falls over under a slowloris attack is an outage, and outages are recoverable in a way that a breach is not. It sits at the bottom of the checklist for that reason, and the pages above it are worth doing first.
That said, it is genuinely cheap, and the one timeout that matters most is frequently missing.
timeout http-request is the one to check
Section titled “timeout http-request is the one to check”timeout http-request limits how long a client may take to send its complete
request headers. It is the direct answer to slowloris-style attacks: opening
many connections and dribbling headers a byte at a time, holding a slot open on
the proxy indefinitely.
It is distinct from timeout client, which governs inactivity on an established
connection and is usually set generously to accommodate slow uploads and long
polls. A generous timeout client with no timeout http-request leaves the
header-reading phase effectively unbounded.
Ten seconds is ample for a real client, which sends its headers in one burst.
The others, briefly
Section titled “The others, briefly”| Timeout | Bounds |
|---|---|
connect |
Waiting for a backend server to accept the TCP connection |
client |
Client-side inactivity once the connection is established |
server |
Waiting for the backend to respond |
http-keep-alive |
Idle time between requests on a kept-alive connection |
queue |
How long a request waits for a free server slot before failing |
Omitting timeout client or timeout server in defaults produces a warning at
startup, because a connection with no timeout on either side can be held until
the process restarts.
maxconn is a decision, not a default
Section titled “maxconn is a decision, not a default”maxconn caps concurrent connections process-wide. Left unset it takes a value
derived from the file descriptor limit, which means your capacity ceiling is
whatever ulimit -n happened to be — a number nobody chose.
Set it explicitly, below what the host can actually sustain in memory. HAProxy
queues beyond the limit rather than crashing, which is the behaviour you want:
predictable refusal instead of the machine going down. Per-backend
maxconn on server lines is separate and protects the backend from being
overwhelmed while HAProxy absorbs the queue.
backend app server app1 10.0.1.10:8080 check maxconn 200Related
Section titled “Related”- Request smuggling — the other consequence of how request framing is handled.
- nginx rate limiting — the same availability question on a different proxy.