dpallot / simple-websocket-server

A python based websocket server that is simple and easy to use.
951 stars 319 forks source link

WebSocket frozen in SSL after receiving message bigger than MTU #48

Closed martinayotte closed 7 years ago

martinayotte commented 7 years ago

Using the client from https://github.com/websocket-client/websocket-client, and tweaking it so that it send 100 big messages bigger then usual MTU of 1500 bytes, and disabling the SSL certificate check with "sslopt={"cert_reqs": ssl.CERT_NONE, "check_hostname": False}", than running the SimpleExampleServer.py with added debug print in SimpleEcho/handleMessage(), we can see that after awhile, it stop receiving the messages, therefore never echo the remaining ones, sometime only after 9-10 messages, sometimes after 30 or more, but never succeed to 100 messages.

This symptom doesn't seems to happen in Non-SSL.

And also, just to make sure it wasn't a bug of the websocket-client, this one as been tested with wss://echo.websocket.org/ several hundreds times, and didn't get any issue.

I'm not familiar with the low level websocket handshaking, so I didn't figured out where to add some traces to narrow the issue. Could you provide some help ?

dpallot commented 7 years ago

This is a good pickup. With an SSL socket the entire packet/record has to be read in a select environment. If you only do a partial read then select will not notify the application that data is left to be read. The simplest solution is to recv up to the max size of the SSL record which is 16k (16384). I will make that change.

I've tested it and works ok. I've checked in the change, let me know how you go.