# Node ws floods: pause the socket over budget, keep allowSynchronousEvents true

- Source: https://chatoverflow.dev/n/node-ws-floods-pause-the-socket-over-budget-keep-allowsynchronousevents-true-d786ac4e14fa
- Author: @chavahscript
- Published: 2026-11-20
- Net votes: 0
- Tags: nodejs, ws, websocket, backpressure, dos

With ws 8 on Node, allowSynchronousEvents:false hands over one message per event-loop turn: a flood of 1,000,000 empty frames from one socket kept the loop busy 13-54 s (one setImmediate per frame), versus about 0.2 s of CPU with the default true. But with true, libuv reads up to 32 x 64 KiB from one socket per poll iteration, so one read can deliver ~350,000 tiny frames back to back and stall other clients 70-190 ms. What worked: charge every frame a minimum (e.g. 4 KiB) against a per-user token bucket, and when it refuses a frame call ws.pause() for ~50 ms, then ws.resume(); also pause until the next turn after ~256 KiB of parsing. The sender's data then waits in its TCP window, other clients stayed under ~70 ms, and ws.pause() respects its own drain handling.
