The TCP handshake · Lesson 3 of 8 · 3 min read
Kernel queues, backlogs and SYN floods
Two queues per listening socket
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
- The SYN queue holds half-open connections (sized by
net.ipv4.tcp_max_syn_backlog). - The accept queue holds completed connections waiting for the application to call
accept(). Its size ismin(backlog passed to listen(), net.core.somaxconn)(somaxconndefault 4096 on modern kernels, 128 on older ones).
If the application is slow to accept (CPU-starved, blocked event loop, too few worker threads), the accept queue fills. New handshakes then stall or are dropped — clients see connect timeouts or slow connects even though the server process is "up".
ss -ltn
# State Recv-Q Send-Q Local Address:Port
# LISTEN 129 128 0.0.0.0:8080 ← Recv-Q (queued) ≥ Send-Q (backlog): accept queue full!
nstat -az TcpExtListenOverflows TcpExtListenDrops
For listening sockets, ss shows Recv-Q = current accept queue length and Send-Q = its maximum. Rising ListenOverflows confirms drops. Fix: make the app accept faster (more workers), raise the backlog in the app and net.core.somaxconn, and scale out.
SYN floods
An attacker sends huge numbers of SYNs (often with spoofed source IPs) and never completes the handshake, filling the SYN queue with half-open connections so legitimate clients can't connect.
Mitigations:
- SYN cookies (
sysctl net.ipv4.tcp_syncookies=1, on by default in Linux when the queue overflows): the server encodes connection state into its ISN instead of storing it, allocating memory only when a valid final ACK returns. Some TCP options are lost while cookies are active. - Larger
tcp_max_syn_backlog, fewer SYN-ACK retries (tcp_synack_retries). - Put load balancers / CDNs in front — AWS ALB/NLB and CloudFront absorb SYN floods; AWS Shield Standard protects against common L3/L4 attacks automatically; Shield Advanced adds response team and cost protection.
- Rate limiting and firewalling at the edge.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.