← blog · November 29, 2026

TCP Listen Queue Overflow: SYN and Accept Queues, somaxconn and One-Second Delays

When application metrics look clean but clients see delays of exactly one or three seconds, connections may be dropped in the kernel's accept queue. How to diagnose it, who sets the limit, and why a bigger queue is usually not the fix.

A service slows down at random under load, yet the request durations the application measures itself look clean. On the client side, some requests take exactly one second longer, others exactly three. Nothing in the error logs, and the CPU is busy but not saturated. The most common cause of this picture is an overflowing listen queue in the kernel: the connection is dropped before it ever reaches the application, the client retries, and the delay shows up in none of the application's metrics.

There are two queues, not one

For every listening TCP socket, Linux keeps two separate queues.

The SYN queue holds half-open connections: the client's SYN arrived, the kernel answered with SYN-ACK, and it is waiting for the final ACK. Its size is related to net.ipv4.tcp_max_syn_backlog. SYN cookies (net.ipv4.tcp_syncookies, enabled on most distributions) let the kernel complete handshakes even when this queue is full by encoding state into the packet.

The accept queue holds completed connections: the handshake is done and the connection is waiting for the application to call accept(). Its size is the smaller of the value the application passes to listen(fd, backlog) and net.core.somaxconn.

In practice the problem is almost always the second one. The accept queue fills up when the application accepts connections more slowly than they arrive. Once it is full, the kernel by default (net.ipv4.tcp_abort_on_overflow=0) ignores the client's final ACK and starts dropping new SYNs as well. The client gets no answer to its SYN and retries after the initial retransmission timeout, usually one second. If that attempt is dropped too, the wait doubles. That is where the "exactly one second, exactly three seconds" pattern on the client comes from.

Diagnosing it

Start with ss. For listening sockets, the Recv-Q column shows how many connections are currently waiting in the accept queue, and Send-Q shows the queue's limit:

ss -ltn

If Recv-Q approaches or equals Send-Q, the queue is filling. This is a point-in-time value; if the problem comes in bursts lasting a few seconds, a single reading can miss it.

The durable evidence is in the counters:

nstat -az TcpExtListenOverflows TcpExtListenDrops

ListenOverflows counts connections dropped because the accept queue was full. ListenDrops includes those plus drops at the listen stage for other reasons. These counters are host-wide and do not tell you which port is affected, so read them together with ss. The "times the listen queue of a socket overflowed" line in netstat -s is the same counter.

A Possible SYN flooding on port ... Sending cookies message in the kernel log means the SYN queue filled. It does not always mean an attack; a legitimate traffic burst produces the same message.

Scrape these counters into your metrics system and alert on any non-zero increase. This counter should stay flat. If it moves, a user is waiting somewhere.

Who sets the limit

Because the queue size is the minimum of two values, you need to know both.

The default for net.core.somaxconn went from 128 to 4096 in kernel 5.4. Hosts on older kernels, or built from an old image, can still show 128. Check with:

sysctl net.core.somaxconn net.ipv4.tcp_max_syn_backlog

The value the application asks for depends on the runtime and is often quietly small:

  • nginx uses 511 by default for the listen directive on Linux; change it with listen 80 backlog=4096;.
  • Node.js uses 511 by default for server.listen().
  • Go's net package reads the value from /proc/sys/net/core/somaxconn on Linux, so it follows the system setting.
  • In Python, socket.listen() without an argument picks a reasonable default, but many frameworks pass their own value. Check the documentation of the server you actually run.

So raising somaxconn to 4096 changes nothing on a setup where nginx asks for 511. The reverse also holds: configuring 8192 in the application is silently cut to 128 if somaxconn is 128, and the application will not tell you.

Containers and Kubernetes

net.core.somaxconn is scoped to the network namespace. Raising it on the host does not affect a container's own namespace. In Docker, set it per container with --sysctl net.core.somaxconn=4096.

In Kubernetes it goes into securityContext.sysctls in the pod spec, but net.core.somaxconn is not on the kubelet's list of safe sysctls. A pod that lands on a node whose kubelet does not allow it via --allowed-unsafe-sysctls will fail to start. If you rely on this setting, put the allowance into the node pool configuration and pin the pod to that pool. Otherwise the next node replacement leaves your pods unable to start.

Is a bigger queue the fix

Here it pays to take a side: a bigger queue only absorbs short bursts; it does not fix a sustained rate mismatch. The accept queue is a buffer. If the application can accept 2000 connections per second and 3000 arrive, the queue fills no matter how large it is. A larger queue only delays the moment it fills, and meanwhile every queued connection waits longer.

Little's law is useful here: average time in the queue equals the number of items in it divided by the accept rate. A full 4096-entry queue in front of an application accepting 2000 per second adds about two seconds of wait to every new connection. If the client timeout is shorter than that, the connection is eventually established but the client has already given up, and the server does work nobody is waiting for.

The right order:

  1. Prove the overflow is real with the counters.
  2. If overflows come in short bursts (a connection storm after a deploy, a load balancer reconnecting all at once), size the queue to cover the burst, raising somaxconn and the application value together.
  3. If overflows are continuous, the problem is the accept rate. Find what slows the accept loop: a single accepting thread, TLS handshakes done on the accepting thread, an exhausted worker pool, or a blocking call on the event loop.
  4. If capacity is genuinely short, scale out and reject excess load early. A fast refusal beats a connection that waits two seconds in a queue and then times out.

Pitfalls

SO_REUSEPORT gives each socket its own queue. nginx's reuseport, or several processes listening on the same port with this option, spreads connections across processes in the kernel and removes contention on the accept lock. But the spread is based on a hash of the connection's addresses and ports, not on how busy each process is. If one worker gets stuck on a long task, its queue fills and overflows while the other workers sit idle. The total counter shows overflows while average load looks low. ss -ltn lists each socket on its own line, and a clear imbalance between those lines is the sign of this trap.

tcp_abort_on_overflow=1 makes the problem visible but does not solve it. With this setting the kernel sends an RST to the client when the queue is full, so the client sees a refused connection instead of a delay. Behind a load balancer that retries, failing fast can help. On a service facing end users directly, it turns a transient burst into a hard error. Leaving the default is usually right.

Load balancer health checks mislead. The health check connects to the same port. When the queue is full, the health check is delayed by a second too; if that crosses the threshold, the instance is pulled from the pool, its load moves to the other instances, and they overflow in turn. Pick a health check timeout that tolerates a one-second SYN retransmission, or serve health checks on a separate port.

Clients without connection pooling amplify the problem. A client that opens a new TCP connection for every request makes the server's accept rate equal to the request rate. Keep-alive and connection pooling cut the number of connections to accept dramatically, and often matter more than any queue tuning.

Coarse scrape intervals hide bursts. On a dashboard averaging over a minute, a few seconds of overflow disappear. Since the counter is cumulative the increase still shows; alert on the presence of an increase, not on its rate.

When not to bother

If a proxy or managed load balancer terminates connections in front of you and opens a small number of persistent connections to the backend, the backend's accept queue rarely matters; the real queue is in the proxy and diagnosis should start there. Likewise, if your application is already CPU-bound, tuning the queue only grows the number of waiting connections. The work then is adding capacity or shedding load; spending time on kernel settings just postpones the problem to the next burst.

In short: start by tracking the ListenOverflows counter. If it stays at zero, you do not need to touch any setting in this post. If it grows, find the socket with ss, read the application's requested value and the system limit together, and before enlarging the queue, ask why the accept rate dropped.

[ ← Back to burak.sh ]