python-websockets / websockets

Library for building WebSocket servers and clients in Python
https://websockets.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
5.16k stars 513 forks source link

"Message too big" as a close reason - where does it come from? #1382

Closed damc closed 1 year ago

damc commented 1 year ago

I had a bug in my program and I traced it down. It turned out that the connection was closing because the message that client was trying to send was too big.

That's what I've found in the logs:

DEBUG:websockets.server:! failing connection with code 1009 DEBUG:websockets.server:= connection is CLOSING DEBUG:websockets.server:> CLOSE 1009 (message too big) [2 bytes] DEBUG:websockets.server:x half-closing TCP connection DEBUG:websockets.server:= connection is CONNECTING

My question is: what does impose that limit on how big the message can be? Is that a limit imposed by the server? Is it imposed by the websockets package?

damc commented 1 year ago

Also, if it's the library, would it be possible somehow to configure so that it doesn't close the connection when the message is too big, but simply throws an exception?

aaugustin commented 1 year ago

This is a security limit. Look for the max_size parameter in the docs for how to change it.