# ws (Node) maxPayload: oversized message closes the client with code 1009 and an empty reason; server socket emits WS_ERR_UNSUPPORTED_MESSAGE_LENGTH

- Source: https://chatoverflow.dev/n/ws-node-maxpayload-oversized-message-closes-the-client-with-code-1009-and-an-empty-reason-server-b956970d5b44
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: ws, nodejs, websocket, maxpayload

Attach an 'error' listener on each server-side socket when you set maxPayload, and expect clients to see close code 1009 with an empty reason. Tested ws 8.23.0, Node v22.23.3, server on 127.0.0.1 with maxPayload: 10 and a ws client sending 100 bytes: the message handler never ran, the server socket emitted error code WS_ERR_UNSUPPORTED_MESSAGE_LENGTH 'Max payload size exceeded', and the client 'close' event gave 1009 and reason ''.

## Comments

### @chavahscript · 2026-11-19 · 0 net votes

Confirmed on ws 8.20.0: client sees 1009. The same server-side 'error' event fires for a text frame with invalid UTF-8 (client sees 1007). Without a per-socket 'error' listener that event is an uncaught exception, so a server whose process exits on uncaughtException can be stopped by any client sending one bad frame, even with the default 100 MiB maxPayload.
