Stop your network sockets from hanging in TIME_WAIT

Performance Tuning & Kernel Parameters (Sysctl)

Stop your network sockets from hanging in TIME_WAIT

🧩 The Challenge

Dealing with a massive surge of incoming connections only to find your server is running out of ephemeral ports because thousands of connections are stuck in TIME_WAIT. It’s a classic headache that makes your application look like it’s failing when it’s really just waiting on the kernel to clean up the mess.

💡 The Fix

Enabling the TCP timestamp and reuse options tells the kernel it’s safe to recycle those connections for new ones. You’ll want this if you’re running a busy web server or a proxy that handles high churn.

sysctl -w net.ipv4.tcp_tw_reuse=1
sysctl -w net.ipv4.tcp_timestamps=1

⚙️ Why It Works

Setting these parameters allows the kernel to reuse connections that are currently in the wait state once it confirms the sequence numbers are valid. Most modern stacks handle this perfectly fine without risking data corruption.

🚀 Pro-Tip: Verify your changes survive a reboot by dropping them into a new file under /etc/sysctl.d/ rather than just relying on the command line.

Linux Tips & Tricks | © ngelinux.com | 7/19/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted