A crawler runs fine for twenty minutes, then every request fails at once. You rotate the IP, the error does not move; you upgrade the line from 5 Mbps to 100 Mbps, it still does not move.

The proxy was never the problem. Your machine ran out of local ports.

Cannot assign requested address means connect() could not reserve a source port. No packet was sent and the proxy has no record of you — the failure sits upstream of the exit.

A connection has four coordinates, and a proxy pins three

A TCP connection is identified by source IP, source port, destination IP, and destination port. Change any one and you have a connection that cannot collide with the old one, which is why a single source port can be reused against a hundred sites when the destination differs each time.

Route everything through one proxy endpoint and that dimension collapses. Source IP is fixed by your single NIC, and the destination is always the same proxy address and port. Three of four coordinates are pinned, leaving only the source port to tell connections apart.

The pool stops being shared and becomes a queue of numbered tickets, one per request. When they run out, connect() fails instantly while the proxy line stays healthy — which is why the same script runs 500 concurrent requests without a proxy and fails the moment SOCKS5 is enabled.

Three numbers decide your ceiling

Sustainable new connections per second is roughly the usable port count divided by how long a closed connection holds its port, minus a margin of about 30 percent.

Platform Ephemeral range Usable ports TIME_WAIT New conns/s (sustained)
Linux (default) 32768–60999 28,232 60 s ~330
Windows (default) 49152–65535 16,384 ~120 s ~95
Linux (widened) 10000–65535 55,535 60 s ~648

The margin covers uneven allocation, the OS and its background DNS lookups, and slow targets that hold a port longer. Even the widest range still leaves you under 650 new connections per second.

Read the error string before you change anything

Five failures look identical on a dashboard and point at five different machines. The literal message is the only reliable discriminator.

Message Where it points What it is not
Cannot assign requested address Local port pool exhausted A blocked IP
Only one usage of each socket address Local bind collision (Windows) Target rate limiting
Too many open files File descriptor limit A port limit
Connection refused / reset by peer Proxy or target closed A local resource issue
SOCKS5 reply 0x02 Proxy policy refused Your port pool

Messages with assign, socket address, or open files describe your own machine; refused, reset, or timeout describe the path.

Python obscures this: requests wraps errno 99 into Max retries exceeded ... Cannot assign requested address, and its retry advice is harmful — every retry is another connect() for the same empty pool.

Ten minutes to confirm or rule it out

# 1. How many ports are stuck in TIME_WAIT? ss -s | grep -i timewait # 2. How large is the pool you are dividing by? cat /proc/sys/net/ipv4/ip_local_port_range # 32768 60999 -> 28,232 # 3. Is the descriptor limit lower than the port limit? ulimit -n # 4. Behind NAT or in a container? The other ledger counts too. sysctl net.netfilter.nf_conntrack_count net.netfilter.nf_conntrack_max # Windows equivalents netstat -ano | findstr TIME_WAIT netsh int ipv4 show dynamicport tcp netsh int ipv4 show excludedportrange protocol=tcp 

Under 60 percent of the pool in TIME_WAIT is comfortable, 60 to 90 is marginal, above 90 means mass failure under any burst. Query the crawler host, not your laptop, and remember that inside a container the tracking table belongs to the host.

Three fixes, and what each one really costs

Do the arithmetic first. At 300 new connections per second with a 60-second TIME_WAIT you hold 18,000 ports at steady state — most of a 28,232 pool, with no room for a spike. At 500 per second you need 30,000, more than the pool holds.

Connection reuse is cheapest: keep-alive and a bounded pool cut the rate of new connect() calls. It only works if your workload tolerates serialising onto fewer sockets.

Widening the range is the middle option, worth at most a doubling. On Windows it needs a reboot, and the new range must dodge segments reserved by Hyper-V, WSL, and Docker, or thousands of "available" ports stay unassignable.

Adding an egress endpoint is the only true multiplier: a second proxy address is a second four-tuple space, a complete new pool. Bandwidth solves a different problem — it makes each connection faster and creates no ports at all.

Four changes that backfire

net.ipv4.tcp_tw_recycle was removed in kernel 4.12. Guides recommending it copy text from a decade ago; on a current kernel the setting does not exist or is ignored.

tcp_tw_reuse applies only to the side that opens the connection and requires timestamps. Behind shared NAT it can let a server treat two connections as one.

SO_LINGER set to 0 frees a port immediately with an RST, but the peer sees an abnormal close and risk systems may count it against you.

Changing the Windows port range without rebooting changes only what netsh reports; allocation keeps the old range, and overlapping an excluded range cancels part of the gain.

FAQ

I rotated through five IPs and the error never changed. Why?
The error occurs before any packet is sent, so the proxy never received a request. Check TIME_WAIT against the port range.

Ports go up to 65,535 — why do I only get 28,232?
That is the ceiling of the port number space, not what is available. Low ports belong to system services, and Linux allocates 32768–60999 to ephemeral connections by default. Windows gives 16,384.

Is TIME_WAIT a fault? Should I flush it?
It is a normal part of teardown, and it stops delayed segments from an old connection being accepted by a new one. Linux releases it after 60 seconds unaided; it only matters near the pool size.

My provider advertises 500 concurrent connections but I fail at 200. Who is wrong?
Neither. Those are two limits and the real ceiling is the smaller one. On a single egress the local port pool arrives first — roughly 330 new connections per second on default Linux, lower for long-lived sockets.

Where this fits

We keep the diagnostic commands and the port, TIME_WAIT, and descriptor limits in one place at 代理IP采集全超时:先查本机端口是否用尽, with a free IP and line check that separates a bad exit from a saturated client.

The rule that survives every version of this problem: measure the smallest of the three limits before paying to raise any of them.