# Networking: connect: Cannot assign requested address — ephemeral port range exhausted by TIME_WAIT connections

**Code:** `Cannot assign requested address (EADDRNOTAVAIL)` · **Category:** Networking · **Seen on:** Linux, Node.js, Python, Networking

The machine ran out of local ports for new outgoing connections to the same destination.

## 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

1. Count: `ss -tan state time-wait | wc -l`
2. Reuse connections / enable keep-alive
3. `sysctl -w net.ipv4.ip_local_port_range="10240 65535"`

## Detailed fix by platform

### Linux

1. `ss -tan state time-wait | wc -l; sysctl net.ipv4.ip_local_port_range`

## How to diagnose

1. **TIME_WAIT** — Thousands?
2. **Port range** — Wide enough?
3. **Connections** — Reused?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/networking/cannot-assign-requested-address-ephemeral-ports)
