Opscraft
The TCP handshake · Lesson 3 of 8 · 3 min read

Kernel queues, backlogs and SYN floods

Two queues per listening socket

Enlarge diagramSYN arrivesSYN queuehalf-openconnections(SYN_RECV)accept queuehandshakesdone, waiting forthe appthe applicationcalls accept()final ACKaccept()SYN queue size: tcp_max_syn_backlog · fills during SYN floods (SYN cookies help)accept queue size: min(listen backlog, somaxconn) · in ss -ltn, Recv-Q ≥ Send-Q means it is full
Figure 1. A listening socket has two queues. If the application calls accept() too slowly, the accept queue fills and new clients stall or time out.
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 is min(backlog passed to listen(), net.core.somaxconn) (somaxconn default 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 diagramWithout SYN cookiesWith SYN cookiesEvery fake SYN takes a slot in the SYN queueThe queue fills; real clients are turned awayConnection details are encoded into the server'ssequence numberNothing is stored until a real client sends the finalACK
Figure 2. A SYN flood fills the SYN queue with handshakes that never finish. SYN cookies let the server answer without storing anything until the client really replies.
Swipe sideways to see all of it, or tap to open it full screen.