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

`ss -tan` shows thousands of sockets in `FIN-WAIT-2` on a server.

IntermediateTroubleshootingSockets, ports, TIME_WAIT and conntrack
Answer

Likely causes → Your side closed and the peer ACKed the FIN, but the peer never sent its own FIN. The remote application is not closing its end (its own CLOSE_WAIT leak), or a middlebox dropped the peer's FIN. Orphaned FIN-WAIT-2 sockets time out after tcp_fin_timeout (60 s default); ones still owned by a process can live longer.

Diagnose →

ss -tano state fin-wait-2 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head
sysctl net.ipv4.tcp_fin_timeout

Then check the peer host for matching CLOSE_WAIT sockets.

Fix → Fix the peer's connection handling. As a mitigation, lower net.ipv4.tcp_fin_timeout to 15–30 s and make sure your app closes sockets fully (not just shutdown(SHUT_WR) and then forgets them).

Prevent → Track TCP state counts per host as a dashboard; asymmetry between peers points straight at the leaking side.

All Networking questions Roadmap: Networking for DevOps

More on Sockets, ports, TIME_WAIT and conntrack