FULL AI ANALYSIS

Node.js + PM2 server exhausts ephemeral ports (TIME_WAIT) during traffic bursts causing upstream connection failures and 502s

Generated Oct 24, 2026, 9:21:01 AM

Analysis summary

Node.js workers create many short-lived outbound TCP connections so local ephemeral ports enter TIME_WAIT for the TCP 2MSL. With default port range and high concurrency, the ephemeral pool is exhausted. Temporary tcp_tw_reuse helped but isn't ideal alone. Safe mitigations: increase ephemeral port range, enable reuse-related sysctls with caution, implement connection pooling or reuse at the app layer, and reduce short-lived connect patterns.

Possible causes

High rate of short-lived outbound TCP connections causing ephemeral port pool exhaustion (TIME_WAIT accumulation)

95%

Application not reusing connections for repeated outbound calls (no pooling for DB/HTTP upstreams)

80%

Too narrow ip_local_port_range configured on host limiting available ephemeral ports

50%

Kernel TCP sysctl settings (tcp_tw_recycle/tcp_tw_reuse) misconfigured causing unpredictable TIME_WAIT behavior

25%

Suggested fixes

1

Diagnostic step 1

Implement connection pooling in the Node app for outbound services (keep-alive agents for HTTP, pooled DB connections) to avoid frequent connects.

2

Diagnostic step 2

Increase ephemeral port range: sysctl -w net.ipv4.ip_local_port_range='15000 61000' and persist in /etc/sysctl.conf.

3

Diagnostic step 3

If safe for your environment, enable tcp_tw_reuse: sysctl -w net.ipv4.tcp_tw_reuse=1 (test carefully; not recommended with NAT requiring strict semantics).

4

Diagnostic step 4

Monitor TIME_WAIT via ss -tan | grep TIME-WAIT | wc -l and track available ports via ss to validate changes.

5

Diagnostic step 5

Deploy changes to one node canary, verify behavior under synthetic burst, and then roll out cluster-wide. Keep a rollback plan to revert sysctls and pool configuration.