Networking: connect: Cannot assign requested address — ephemeral port range exhausted by TIME_WAIT connections
The machine ran out of local ports for new outgoing connections to the same destination.
Cannot assign requested addressconnect: Cannot assign requested addressOSError: [Errno 99] Cannot assign requested addressError: connect EADDRNOTAVAIL Meaning
Each connection needs a unique source IP:port pair per destination, and closed connections linger in TIME_WAIT. Reuse connections (keep-alive, pools), widen net.ipv4.ip_local_port_range, add more source IPs, and avoid opening a new connection per request.
Common causes
- No connection pooling or keep-alive
- Huge connection churn to one destination
- Small ephemeral port range
- Many sockets in TIME_WAIT
- Behind a single NAT/proxy IP
⚡ Quick fix
- Count:
ss -tan state time-wait | wc -l - Reuse connections / enable keep-alive
sysctl -w net.ipv4.ip_local_port_range="10240 65535"
Detailed fix by platform
Linux
ss -tan state time-wait | wc -l; sysctl net.ipv4.ip_local_port_range
How to diagnose
- TIME_WAIT — Thousands?
- Port range — Wide enough?
- Connections — Reused?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- 4-way handshake timeout / Incorrect password Networking: wlan0: WPA: 4-way handshake failed - pre-shared key may be incorrect / WRONG_KEY
- arp -a shows (incomplete) Networking: `arp -n` shows (incomplete) / Destination Host Unreachable — no ARP reply from the next hop
- Connections hang on large transfers (PMTU black hole) Networking: SSH/HTTPS connects but hangs on large data — path MTU discovery black hole
Most viewed in Networking
- Rogue DHCP server hands out wrong gateway/DNS Networking: Clients receive the wrong default gateway or DNS server — a rogue DHCP server (often a home router) answers first
- Idle connections silently dropped by firewall/NAT Networking: Connection works, then fails after being idle — firewall/NAT idle timeout dropped the TCP session (use keepalive)
- dig: status: SERVFAIL (DNSSEC validation failed) Networking: dig: ;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL — resolver failed to answer (DNSSEC validation or upstream failure)
Other ways to find it
Where this error sits
Origin: Network. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026