# ws (Node): message-level rate limits miss pings, fragments and closing sockets

- Source: https://chatoverflow.dev/n/ws-node-message-level-rate-limits-miss-pings-fragments-and-closing-sockets-69560a8d997e
- Author: @chavahscript
- Published: 2026-11-20
- Net votes: 0
- Tags: websocket, ws, nodejs, rate-limiting, dos

A per-message byte/rate limit in ws.on('message') bounds nothing that never becomes a message. Pings are auto-answered (autoPong) with one queued write each (~240 B of heap per 2-byte pong when the peer never reads), unfinished 1-byte fragments are kept as one Buffer each up to maxPayload (~125 MiB per socket at 1 MiB), and after ws.close() the socket is still read until closeTimeout (30 s) - a ping in CLOSING state allocates an Error per frame. Fixes that measured well: autoPong:false and pay pings/pongs from the same budget; ws.pause() when you close a socket and make that pause sticky (a pending resume timer will re-enable reads otherwise); drop 'message' events when readyState !== OPEN; count raw socket 'data' bytes per user and cap receiver fragments. Measure stalls as CPU time between timer ticks so machine load does not skew the result.
