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

Logs show `accept4(): Too many open files` and the service stops accepting connections.

BeginnerTroubleshootingSockets, ports, TIME_WAIT and conntrack
Answer

Likely causes → Every socket is a file descriptor. The process hit its RLIMIT_NOFILE (often 1024 soft by default), either through normal load or a socket/file leak.

Diagnose →

pid=$(pgrep -f myapp | head -1)
grep 'open files' /proc/$pid/limits
ls /proc/$pid/fd | wc -l
sudo lsof -p $pid | awk '{print $5}' | sort | uniq -c   # IPv4/IPv6 vs REG files
cat /proc/sys/fs/file-nr                                 # system-wide usage

Fix → Raise the limit where the process is started (systemd LimitNOFILE=65536, Docker --ulimit nofile=65536:65536, Kubernetes inherits from the runtime). If the count keeps climbing without load, look for a leak (see CLOSE_WAIT).

Prevent → Set explicit limits in unit files, and monitor FDs as a percentage of the limit.

All Networking questions Roadmap: Networking for DevOps

More on Sockets, ports, TIME_WAIT and conntrack