한국어English日本語简体中文繁體中文DeutschไทยTiếng ViệtРусскийPortuguês (Brasil)EspañolBahasa Indonesia

Game Lag White Paper › L7 Server OS (kernel)

Ephemeral port exhaustion on server-to-server connections Ephemeral port exhaustion (TIME_WAIT)

Cause ID so-ports · Primary owner Game team (Server development) · Also Infra team (Server infrastructure)

Open the interactive card with figures and simulations →

When a game server opens and closes short connections to the DB or other servers very often, closed connections hold their ports for a while, and new connections can’t be opened.

Why A new connection is opened and closed for every request → Effect The side that closes first holds the port for about 60 seconds on Linux (TIME_WAIT), and the pool of usable ports runs dry → On screen Internal requests fail: failed saves, broken features

Symptoms
Dropped action / rollback, Can’t connect / infinite loading
Factors
Packet loss
Who’s affected
Whole server, One feature only
When
When crowds gather
Owner
Primary owner Game team (Server development) · Also Infra team (Server infrastructure)
Game team action items
Reuse connections (connection pool), stop opening and closing a new connection for every request.
Infra team action items
Widen the port range (ip_local_port_range), consider TIME_WAIT reuse for outgoing connections (tcp_tw_reuse on Linux), monitor the TIME_WAIT count.
Ballpark numbers
The default Linux port range (32768–60999) holds about 28,000 ports. More than 470 new connections per second to the same destination address use them up. Windows has about 16,000 ports by default (49152–65535) and a longer TIME_WAIT, so it runs out even faster.
On the graph
Hits a ceiling · TIME_WAIT sockets, internal connection failures
Where to look
TIME_WAIT sockets counted per destination address with ss -tan state time-wait, and connect failures (EADDRNOTAVAIL) in the game server log
Confirmed if
TIME_WAIT sockets to the same destination (the DB, for example) flatten near the size of the ephemeral port range (about 28,000 by default), and connect fails with EADDRNOTAVAIL
Ruled out if
Few TIME_WAIT sockets, but only outbound connections to the outside fail: “Cloud NAT gateway connection and port limits”
Check with
Infra tools (no game code needed)
Learn more
On Linux, the 60-second TIME_WAIT is hard-coded in the kernel. Lowering tcp_fin_timeout, which has a similar name, doesn’t shorten TIME_WAIT.

Sources

  1. IP Sysctl Linux kernel
    ip_local_port_range default 32768–60999; tcp_tw_reuse; tcp_fin_timeout is how long the FIN_WAIT_2 state is kept
  2. include/net/tcp.h (Linux v6.12) Linux kernel
    TCP_TIMEWAIT_LEN (60*HZ): the roughly 60-second TIME_WAIT is a kernel constant
  3. TCP/IP port exhaustion troubleshooting Microsoft
    Windows dynamic ports default to 49152–65535, and a closed connection holds its port in TIME_WAIT for 4 minutes by default
  4. ss(8) — Linux manual page iproute2
    The state filter state time-wait shows only TIME_WAIT sockets
  5. connect(2) — Linux manual page Linux man-pages
    EADDRNOTAVAIL: every port in the ephemeral port range is in use, so the connection can’t be opened

See also

Same layer: L7 Server OS (kernel)

Same symptom (Dropped action / rollback), other layers

View the interactive card with figures and simulations