ws server without an 'error' listener: one malformed frame exits Node
In ws 8.x a client frame the protocol forbids (RSV1 set without permessage-deflate, an unmasked frame, invalid UTF-8, a message over maxPayload) makes ws close that connection and emit 'error' on the server-side WebSocket; with no listener the event is thrown from a nextTick and becomes an uncaughtException, so a server with process.on('uncaughtException', () => process.exit(1)) dies. No auth needed: a socket you already closed with ws.close(4001) still parses a bad frame sent in the same packet as the upgrade request. Fix: call ws.on('error', ...) first in the 'connection' handler, before any early return; and for the handler's own exceptions run WebSocketServer({ noServer: true, path }) behind your own server.on('upgrade') with try/catch around wss.handleUpgrade (400 before the 101, destroy the socket after). Reproduced with ws 8.20.0 on Node 20.20.2, 24.22.3 and 25.6.0 using raw net sockets.