Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Resolving EADDRNOTAVAIL & 60s TIME_WAIT
Port Exhaustion at 30,000 RPS.

Outbound REST calls fail with EADDRNOTAVAIL within 1 second of a 30,000 RPS burst despite low CPU and RAM.
Start the journey3 stages· Last modified Nov 29, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When resolving TIME_WAIT port exhaustion, move HTTP/gRPC clients to process-wide bounded pools.

TL;DR30-second simplified summary
▾

Bounded Keep-Alive pools eliminate EADDRNOTAVAIL and handshake overhead.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Linux ss / netstat socket state inspection
Core prerequisite: Linux ss / netstat socket state inspection.
HTTP Keep-Alive vs. Connection: close
Core prerequisite: HTTP Keep-Alive vs. Connection: close.
Full walkthrough · 3 stages
01
STAGE 01L4 · FUNDAMENTALS

Diagnosing EADDRNOTAVAIL with ss -tan.

Running ss -s shows ~28,000 sockets in TIME_WAIT to the same destination IP:port while CPU sits under 25%.

Ephemeral Port Saturation

Per-Request Client vs. Singleton Connection Pool

Before · Per-Request HTTP Client (30,000 RPS)
  • 28,232 sockets in TIME_WAIT
  • connect() fails with EADDRNOTAVAIL in 0.94s
After · Singleton Keep-Alive / HTTP2 Pool
  • 200 sockets in ESTABLISHED (0.71% port usage)
  • 0 TIME_WAIT churn
02
STAGE 02L4 · FUNDAMENTALS

Deploying Bounded Java/Python Client Pools.

Replace per-call HttpClient / httpx.Client creation with a process-wide singleton pool.

Pooled Socket Lifecycle

Bounded Connection Pool Reuse Cycle

lease connectionwrite HTTP requestread responsekeep-alive reuseIdle PoolUp to 200 ESTABLISHED soAcquired SocketLeased to outbound requeIn-Flight I/OSend request & read respReturned to PoolReused without TCP hands
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(200);
cm.setDefaultMaxPerRoute(200);
CloseableHttpClient client = HttpClients.custom().setConnectionManager(cm).build();
03
STAGE 03L5 · APPLIED DESIGN

Preventing Synchronized Idle-Expiry Storms.

Stagger keepalive_expiry across pods so 200 connections do not close simultaneously. [INSERT YOUR BENCHMARK / PROD NOTE] for p99 improvement.

Egress Pool Topology

Singleton Pool with Jittered Keep-Alive Expiry

API Router Pod30,000 RPS IngressSingleton PoolmaxTotal=200 +…Linux TCP Stack200 ESTABLISHED / 0…Downstream Servicedst_ip:dst_portborrow socketreuse fdpersistent Keep-Alive/ HTTP2
Engineering Decision Framework
Problem
How to sustain 30,000 RPS outbound REST/RPC traffic without exhausting the host's 28,232 ephemeral ports into 60-second TIME_WAIT or triggering synchronized idle-expiry FIN storms.
Naive Solution
Instantiate a fresh HTTP client per request or set a uniform idle keepalive_expiry across all pods without connection pooling.
Why It Fails
Per-request clients close every TCP connection after one call, filling all 28,232 ephemeral ports in 0.94s and causing EADDRNOTAVAIL; uniform keepalive_expiry causes all 200 pooled sockets to close and reconnect simultaneously.
Alternatives
Tuning kernel tcp_tw_reuse or adding more downstream servers vs. process-wide bounded Keep-Alive/HTTP2 connection pooling with jittered idle expiry.
Engineering Decision
Use a process-wide singleton bounded Keep-Alive or HTTP/2 connection pool (e.g., maxTotal=200, defaultMaxPerRoute=200) with staggered keepalive_expiry across pods for any service seeing EADDRNOTAVAIL or high TIME_WAIT counts on egress.
Trade-Offs
Eliminates TIME_WAIT port exhaustion and handshake overhead in exchange for managing pool bounds, health/idle eviction, and inbound listener limits separately (somaxconn/ulimit).
Decision Exercise · Make the Call

Why didn't scaling the downstream server add more ephemeral ports on the client?

ChoiceWhat it buysWhat it costs
Unpooled Client (Per-Request)Zero shared connection state across requests No idle-expiry coordination requiredTIME_WAIT Sockets: ~28,232 EADDRNOTAVAIL Rate: 95%+ after 0.94s
Pooled Keep-Alive / HTTP2 (Singleton)TIME_WAIT Sockets: ~0 EADDRNOTAVAIL Rate: 0%Must bound maxTotal and defaultMaxPerRoute (e.g., 200) Requires jittered keepalive_expiry to avoid synchronized FIN storms
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 1
Score: 0/1

Which symptom immediately points to ephemeral port exhaustion rather than downstream CPU saturation?

Recommended Learning Flow