Stop letting your web servers sit on a mountain of wait state sockets
Performance Tuning & Kernel Parameters (Sysctl)
Stop letting your web servers sit on a mountain of wait state sockets
🧩 The Challenge
Dealing with a massive spike in incoming requests usually means your server ends up with thousands of sockets stuck in TIME_WAIT. You end up watching your netstat output freeze while the kernel holds onto those file descriptors for way longer than they need to exist.
💡 The Fix
Enabling the TCP reuse setting lets the kernel recycle those dead connections for new requests, which is a lifesaver when you are running a high-traffic API. It basically stops your server from exhausting its local port range during a traffic burst.
sysctl -w net.ipv4.tcp_tw_reuse=1
⚙️ Why It Works
Setting this flag tells the Linux network stack that it is safe to reuse a socket in the TIME_WAIT state for a new connection if the timestamp sequence is valid. It bypasses the default two-minute waiting period, keeping your ephemeral port pool wide open.
🚀 Pro-Tip: Double check your load balancer config first, because sometimes the problem is just your own proxy hogging the connections before they even reach the app.
Linux Tips & Tricks | © ngelinux.com | 10/30/2026
