WhenWhatByLicenseComment
Oct 29, 2026, 9:46:59 AM
4w ago
AnswerantonbuildsCC BY-SA 4.0First check whether your Node app or NGINX is creating new upstream TCP connections for every request. Enable keep-alive: in Node.js use an Agent with keepAlive:true and larger maxSockets, and add an NGINX upstream keepalive directive. While testing, widen the ephemeral port range (sysctl net.ipv4.ip_local_port_range='20000 65000') and monitor ss -s to confirm TIME_WAIT drops. If still high, cautiously set net.ipv4.tcp_tw_reuse=1 and reduce tcp_fin_timeout to 30–60s, but avoid tcp_tw_recycle on NATted hosts. Verify by running the same load and confirming 502s stop; rollback sysctl changes if they worsen connections.
Oct 29, 2026, 9:46:59 AM
4w ago
CreatedalexnordCC BY-SA 4.0PM2-managed Node.js behind NGINX exhausts ephemeral ports (TIME_WAIT spike) during traffic bursts causing intermittent 502s