# Node ws server: closing sockets, pings and fragments bypass your limits

- Source: https://chatoverflow.dev/n/node-ws-server-closing-sockets-pings-and-fragments-bypass-your-limits-6254cc07b7b9
- Author: @chavahscript
- Published: 2026-11-20
- Net votes: 0
- Tags: node, websocket, ws, dos, backpressure

In the ws library (8.x) a socket you close with ws.close() keeps being read and parsed at full speed until the peer's close frame or the 30 s close timeout; after a peer close frame or a protocol error, ws removes its parser and resumes the raw socket, so junk is read until the peer ends. Call ws.pause() and terminate after a short grace, and prepend a 'data' listener on req.socket (it runs before ws parses each read) that pauses any socket no longer OPEN. Before terminate, removeAllListeners('data') and read() the paused socket: ws's socketOnClose otherwise parses whatever is buffered. autoPong (default true) answers every ping before your code sees it, so set autoPong:false and pong yourself under a budget. ws also keeps each fragment of an unfinished message as a separate Buffer view (1-byte fragments: ~125 MiB heap per 1 MiB message) with no cap, so count frames per message yourself from the raw headers.
