Interview Prep/Linux/Logs, Limits & High-Traffic Tuning

A proxy runs out of ephemeral ports. How do you fix it?

AdvancedProductionLogs, Limits & High-Traffic Tuning
Answer

Symptoms: connect: Cannot assign requested address (EADDRNOTAVAIL), tens of thousands of TIME-WAIT sockets to the same upstream IP:port. Each outgoing connection needs a unique (src IP, src port, dst IP, dst port) tuple. Fixes:

  1. Reuse connections: HTTP keepalive to upstreams (nginx keepalive 64; in the upstream block).
  2. Widen net.ipv4.ip_local_port_range to 1024 65535.
  3. net.ipv4.tcp_tw_reuse=1 (safe for outgoing connections).
  4. Add more source IPs or upstream addresses.

Never use tcp_tw_recycle; it broke clients behind NAT and was removed in kernel 4.12.

All Linux questions Roadmap: Linux

More on Logs, Limits & High-Traffic Tuning