An app server's `CLOSE_WAIT` count grows steadily until the service logs `Too many open files`.
IntermediateTroubleshootingSockets, ports, TIME_WAIT and conntrack
Answer
Likely causes → CLOSE_WAIT means the peer closed the connection and the kernel is waiting for your application to call close(). It is always an application bug: a leaked HTTP client response body, a DB connection not returned to the pool, or a thread blocked forever before cleanup. The kernel never times these out.
Diagnose →
ss -tanp state close-wait | awk '{print $4, $NF}' | sort | uniq -c | sort -rn | head
ls /proc/$(pgrep -f myapp)/fd | wc -l
# Java: jstack <pid> to see threads stuck around the socket; Go: check for missing resp.Body.Close()
The remote address tells you which dependency's connections are leaking.
Fix → Fix the code path (close response bodies, use try-with-resources/defer, set client timeouts so blocked calls return). Restarting the process clears them only temporarily.
Prevent → Alert on CLOSE_WAIT count per process and on open FD count versus the limit.
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?BeginnerLogs 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.AdvancedA blog post told you to set `net.ipv4.tcp_tw_recycle=1`, but `sysctl` returns `cannot stat /proc/sys/net/ipv4/tcp_tw_recycle`.Beginner