Implement reliable WebSocket connections with proper reconnection, heartbeats, and scaling.
onclose firesdelay * (0.5 + Math.random())—prevents synchronized reconnection stormsreadyState: 0=CONNECTING, 1=OPEN, 2=CLOSING, 3=CLOSED—check before sendingbufferedAmount shows queued bytes—pause sending if backpressure buildingwss://host/ws?token=xxx—simple but logged in access logsproxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 3600s;
proxy_read_timeout must exceed your ping interval—default 60s too shortbufferedAmount—memory grows unbounded if client slower than server