Clients that vanished (laptops closed, mobile networks switched) leave connections `ESTAB` on the server for days.
IntermediateTroubleshootingSockets, ports, TIME_WAIT and conntrack
Answer
Likely causes → TCP has no traffic on an idle connection, so if the client disappears without a FIN/RST, the server never notices. These half-open connections hold FDs and memory. TCP keepalive is off by default per socket, and even when on, the default first probe is after 7200 s.
Diagnose →
ss -tno state established '( sport = :5000 )' | grep -c keepalive
sysctl net.ipv4.tcp_keepalive_time net.ipv4.tcp_keepalive_intvl net.ipv4.tcp_keepalive_probes
ss -o shows timer:(keepalive,...) only for sockets with SO_KEEPALIVE set.
Fix → Enable SO_KEEPALIVE in the app and tune it, e.g. 60 s idle, 10 s interval, 6 probes:
sudo sysctl -w net.ipv4.tcp_keepalive_time=60 net.ipv4.tcp_keepalive_intvl=10 net.ipv4.tcp_keepalive_probes=6
Better still, add application-level heartbeats/idle timeouts (WebSocket pings, gRPC keepalive).
Prevent → Set idle timeouts at every layer and keepalive intervals shorter than the shortest middlebox idle timeout.
More on Sockets, ports, TIME_WAIT and conntrack
`dmesg` is full of `nf_conntrack: nf_conntrack: table full, dropping packet` and new connections randomly time out.Intermediate`ss -s` on a reverse proxy shows 40,000 sockets in `TIME_WAIT`. Is that a problem?BeginnerAn app server's `CLOSE_WAIT` count grows steadily until the service logs `Too many open files`.IntermediateLogs show `accept4(): Too many open files` and the service stops accepting connections.Beginner`dmesg` shows `TCP: request_sock_TCP: Possible SYN flooding on port 443. Sending cookies.`Intermediate`ss -ltn` shows the listener for port 8080 with `Recv-Q 129` and `Send-Q 128`, and clients hang on connect.Advanced