---
title: "Cannot assign requested address when calling a dependency | Proofline"
description: "This error comes from the client's own kernel, before any packet leaves: connect() found no free local port for the destination."
url: https://proofline.sh/learn/cannot-assign-requested-address-ephemeral-ports/
---

[Learning center](/learn/)

# Cannot assign requested address when calling a dependency

This error comes from the client's own kernel, before any packet leaves: connect() found no free local port for the destination. Count the client's sockets to that destination, and the ones in TIME\_WAIT in particular, and compare the count with the local port range. A dependency that is down or a NAT gateway out of ports fails differently, after a wait.

Capacity overruns The Proofline team November 23, 2026 5 min read

## What the error says

On Linux, `connect()` returns `EADDRNOTAVAIL` when the socket was not bound to an address beforehand and, while binding it to an ephemeral port, the kernel found every port in the ephemeral port range in use. Runtimes print the standard message for that errno, `Cannot assign requested address`, often together with the errno name and the destination address. [connect(2)](https://man7.org/linux/man-pages/man2/connect.2.html) · [errno names and messages](https://docs.python.org/3/library/errno.html)

The range is `/proc/sys/net/ipv4/ip_local_port_range`, which defaults to 32768 to 60999, or 28,232 ports. Ports listed in `ip_local_reserved_ports` are excluded from automatic assignment. [ip-sysctl](https://docs.kernel.org/networking/ip-sysctl.html)

A port chosen at `connect()` time can be shared by connections to different destinations, as long as the 4-tuple of local address, local port, remote address and remote port stays unique. So the budget is per destination: about 28,000 simultaneous sockets from one client address to one dependency address and port. A client that calls `bind()` with port 0 before connecting reserves the port outright, which uses the range much faster. [IP\_BIND\_ADDRESS\_NO\_PORT](https://man7.org/linux/man-pages/man2/IP_BIND_ADDRESS_NO_PORT.2const.html)

## Why the ports run out

The usual cause is connection churn. The side of a TCP connection that closes first lingers in TIME-WAIT for twice the maximum segment lifetime, and its local port stays tied to that 4-tuple meanwhile. A client that opens a new connection for each request and closes it, such as an HTTP client with keep-alive turned off or a pool that discards connections after each use, leaves one TIME-WAIT socket per request. At a few hundred requests per second to one address, those sockets can fill the range. [RFC 9293 TIME-WAIT](https://www.rfc-editor.org/rfc/rfc9293.html)

The other cause is too many open connections: a pool without a maximum, or a connection leak, holding thousands of established sockets to the same dependency.

## Nearby causes that look similar

| Error | Where it fails | Wait before the error |
| --- | --- | --- |
| `EADDRNOTAVAIL` | Client kernel | None |
| Connect timeout | Path drops the SYN | The connect timeout |
| `ECONNREFUSED` | Destination host resets | One round trip |

A NAT gateway out of ports drops the new connection on the way out, so the client waits for its connect timeout and its kernel reports nothing unusual. That case shows in the gateway's metrics, not on the host. [NAT gateway port allocation](/learn/nat-gateway-port-allocation-errors/) · [Refused or timed out](/learn/connection-refused-vs-timeout/)

On Linux the errno that reports port exhaustion differs between `connect()`, `bind()`, `listen()` and `sendto()`, so a client that binds first may log a different error for the same shortage. [ip(7) bugs](https://man7.org/linux/man-pages/man7/ip.7.html)

## Count the sockets on the client

Run these inside the client's network namespace: on the host for a VM, or in the container for a task or pod (ECS Exec, `kubectl exec`). A container has its own namespace, and Kubernetes treats `net.ipv4.ip_local_port_range` as a namespaced sysctl that a pod can set, so read the range from inside. All commands below only read. [ss(8)](https://man7.org/linux/man-pages/man8/ss.8.html) · [Kubernetes namespaced sysctls](https://kubernetes.io/docs/tasks/administer-cluster/sysctl-cluster/)

```
cat /proc/sys/net/ipv4/ip_local_port_range
cat /proc/sys/net/ipv4/ip_local_reserved_ports

# summary of socket counts by state
ss -s

# sockets to the dependency, by state
ss -Htan state time-wait dst DEPENDENCY_IP | wc -l
ss -Htan state established dst DEPENDENCY_IP | wc -l

# timer on the waiting sockets
ss -tano state time-wait dst DEPENDENCY_IP | head
```

Compare the TIME-WAIT and established counts for the one destination with the size of the range. If together they come near it, the host is out of ports for that destination. The `-o` output shows a `timewait` timer on each waiting socket, which tells you how long they will hold their ports. Run the counts twice, a minute apart: a count that refills as fast as it drains is churn, and a flat established count that only grows is a pool or a leak.

Read `tcp_tw_reuse` too. It defaults to 2, which enables reuse of TIME-WAIT sockets for loopback traffic only, and the kernel documentation says not to change it without expert advice. [ip-sysctl](https://docs.kernel.org/networking/ip-sysctl.html)

```
cat /proc/sys/net/ipv4/tcp_tw_reuse
```

## What each count means

| Observation | Points to |
| --- | --- |
| Thousands in TIME-WAIT to one address | New connection per request |
| Thousands established to one address | Pool without a cap, or a leak |
| Counts far below the range | Not this host; check bind() use and the NAT gateway |
| Error only from one host | That host's churn or pool |

## A worked fixture: one error, two owners

This fixture is illustrative. The fictional service `checkout` calls `orders` at `10.0.4.20:8080`. At 12:10 UTC some `checkout` requests fail at once with `EADDRNOTAVAIL` (`Cannot assign requested address`) calling `10.0.4.20:8080`, while calls to `payments` from the same task succeed.

In the first case, `ss -Htan state time-wait dst 10.0.4.20` counts 27,900 sockets and the established count is 40. The range is the default 32768 to 60999. A release at 11:55 replaced the HTTP client and turned keep-alive off, so each of about 470 requests per second to `orders` opens a connection and closes it, and each close leaves a TIME-WAIT socket holding a port. `payments` is a different destination, so its connections use separate 4-tuples and still work. Restoring connection reuse in the client stops the error.

In the second case, the TIME-WAIT count is 300 and the established count to `10.0.4.20` is 28,100 and rising by a few hundred a minute. The pool has no maximum and a code path returns without releasing its connection. The ports are held by open connections, and the fix is the leak. [Pool waits and slow databases](/learn/connection-pool-timeout-or-slow-database/)

## Limits

`ss` shows the state at the moment you run it; an error that lasted a minute during a burst may be gone when you look. Repeated counts, or a metric of socket states if your hosts export one, cover the gap. The counts tell you which destination fills the range, not which code path opens the connections; pair them with the release diff or client settings.

Raising the port range or enabling reuse changes the kernel's behavior for every service on the host or in the pod. Those are configuration changes, outside a read-only investigation. [Read-only investigation](/learn/read-only-production-investigation/) · [All runtime dependency guides](/learn/runtime-dependency-failures/)

## Questions

### Why does only one destination fail?

The kernel can reuse a local port for connections to different destinations, because the 4-tuple stays unique. Exhaustion happens per remote address and port, so the busiest dependency fails first while others keep connecting.

### Is TIME-WAIT on the client a bug?

No. The side that closes the connection first holds TIME-WAIT, as TCP requires. It becomes a problem only when the client closes connections so often that the waiting sockets fill the port range for one destination.

### How is this different from a NAT gateway running out of ports?

`EADDRNOTAVAIL` fails immediately on the client host. A NAT gateway out of ports drops the connection after it leaves the host, so the client waits for a connect timeout and the evidence is in the gateway's metrics.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Connections fail through a NAT gateway that has run out of ports](/learn/nat-gateway-port-allocation-errors/)
    
    Capacity overruns The Proofline team November 23, 2026 6 min read
    
-   ### [Connection refused or timed out: what each error tells you](/learn/connection-refused-vs-timeout/)
    
    Network outages The Proofline team November 23, 2026 6 min read
