Interview Prep/Networking/Sockets, ports, TIME_WAIT and conntrack

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.

All Networking questions Roadmap: Networking for DevOps

More on Sockets, ports, TIME_WAIT and conntrack