The symptom#
Clients of the fictional orders service log connect timeouts, or connects that take whole seconds, during bursts. The orders dashboards show low CPU and a request rate that dips exactly when clients complain. The network path checks out: security groups allow the traffic, and a single nc -vz from a client usually succeeds.
Three causes look like this:
- The accept queue is full. The application accepts connections more slowly than they arrive: an event loop blocked by synchronous work, a worker pool with every thread busy, or a process paused by garbage collection.
- The path drops packets intermittently, for example a NAT device out of ports or a connection-tracking table that is full. NAT gateway port allocation errors
- The client itself waits before connecting, in a pool queue or DNS lookup, and logs the wait as connect time. Client-side or server-side latency
Why the dependency looks idle#
A TCP connection completes its handshake in the kernel and then waits in the listening socket's accept queue until the application calls accept(). The backlog argument to listen() sets the length of that queue for fully established connections; the queue for half-open connections is limited separately by tcp_max_syn_backlog. A backlog larger than net.core.somaxconn is silently capped to it. Since Linux 5.4 that default is 4096; earlier kernels used 128. listen(2) · ip-sysctl: somaxconn
When a SYN arrives and the accept queue is full, kernels from 4.10 drop the SYN and count it in TcpExtListenOverflows and TcpExtListenDrops. The client gets no answer and retransmits the SYN on its backoff timer, so a connect that would take a millisecond takes a second or more, and fails if every retry meets a full queue. Older kernels completed the handshake and kept the connection half-open instead, which makes the client believe it connected. Kernel SNMP counters · tcp(7): tcp_syn_retries
The application never sees the dropped connections, so its request metrics stay low. The stall that fills the queue also stops the application from recording work. With tcp_abort_on_overflow enabled (it is off by default) the kernel resets overflowing connections instead, and clients see refusals or resets. ip-sysctl: tcp_abort_on_overflow
Read the queue and the counters#
Run these on the dependency's host or inside its container, where the listening socket lives. They read state only.
ss -lnt 'sport = :8080'
For a listening socket, Recv-Q is the number of connections currently waiting in the accept queue and Send-Q is the queue's maximum, after the somaxconn cap. The kernel's diagnostics code fills those two fields from the socket's current and maximum accept backlog when the socket is in the listen state. A Recv-Q at or near Send-Q while clients complain is the overflow in progress. ss(8) · Linux tcp_diag.c
State Recv-Q Send-Q Local Address:Port
LISTEN 129 128 0.0.0.0:8080
Then read the counters. nstat normally records a history file so the next run shows increments; -s leaves that history alone, -a prints absolute values and -z includes counters that are zero. nstat(8)
nstat -asz TcpExtListenOverflows TcpExtListenDrops
sysctl net.core.somaxconn net.ipv4.tcp_max_syn_backlog net.ipv4.tcp_abort_on_overflow
The counters cover every listener in the network namespace since boot, so read them twice a minute apart during an episode and compare. TcpExtListenDrops also rises for other drops on listening sockets, such as memory allocation failures; TcpExtListenOverflows is the one that names a full accept queue. Kernel SNMP counters
Check the application's own backlog as well. Many servers pass a fixed backlog to listen(), and the effective queue is the smaller of that and somaxconn, which Send-Q shows directly.
Decision table#
| On the dependency's host | Points to |
|---|---|
Recv-Q near Send-Q, ListenOverflows rising | Accept queue overflow: the application accepts too slowly |
Send-Q small, such as 128, and bursts overflow it | A low backlog or somaxconn, plus a slow accept loop |
| Queue empty, counters flat, clients still slow | Not the listener: check the path or the client |
| Clients get refused or reset at bursts, counters rising | Overflow with tcp_abort_on_overflow on |
ss shows no listener on the port | The service is down, see refused or timed out |
A worked example with two outcomes#
This example is illustrative. checkout calls orders at 10.0.12.34:8080. Between 12:00 and 12:05 UTC, a tenth of checkout's connects to orders take more than one second and a few time out after three seconds. orders reports 40% CPU and fewer requests than usual.
In the first outcome, ss -lnt 'sport = :8080' on the orders host shows Recv-Q 129 against Send-Q 128, and TcpExtListenOverflows rises by about 2,000 between two readings a minute apart. The orders process log shows garbage-collection pauses of several hundred milliseconds in the same minutes. The application stops accepting during each pause, the queue fills and the kernel drops SYNs. Shortening the pauses or accepting on more threads addresses the cause; a larger backlog only absorbs longer bursts.
In the second outcome, Recv-Q stays at 0 and the overflow counters do not move. Packet captures on both ends show checkout retransmitting SYNs that never arrive at orders. The listener is fine; something on the path is dropping packets, and the investigation moves to the NAT device and connection tracking between them.
Limits#
You need a shell on the dependency's host or container, which managed databases and load balancers do not give you. For those, the provider's own connection and surge metrics are the nearest equivalent. A load balancer in front of the dependency terminates the client's connection, so overflow on the backend shows up as load balancer errors or slow responses, not as the client's connect delay. The counters are per network namespace and cumulative, and ss shows only the current moment, so sample during an episode. This guide reads the listening side only; the runtime dependency failures hub lists the client-side and path checks.
Questions#
What do Recv-Q and Send-Q mean on a listening socket?
For a socket in the listen state, Recv-Q is how many established connections are waiting to be accepted and Send-Q is the maximum that queue can hold. On other sockets they are byte counts, so read them differently.
Why do clients see connects of about one or three seconds?
The kernel dropped their first SYN because the queue was full, and the client's TCP retransmitted it after its retransmission timer: one second at first, doubling on each retry. A connect that succeeds on the first or second retransmission takes about one or three seconds in total. RFC 6298
Will raising somaxconn fix it?
Only if the queue is small for normal bursts. If the application stops accepting for long stretches, a longer queue just holds more clients waiting, and they time out anyway.