dpallot / simple-websocket-server

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

Handle SSLWantReadError and SSLWantWriteErrors on recv and send. #100

Closed GeertL closed 2 years ago

GeertL commented 3 years ago

When using SSLSocket, recv() and send() may raise SSLWantReadError or SSLWantWriteError when the SSL socket is not yet ready to receive or send. In my experience, this tends to occur when e.g. sending large messages.

Currently, the SimpleWebSocketServer can't handle this and will drop the connection even though the connection is fine. Python docs recommend to catch these and retry after another call to select(). This PR adds try/except for SSLWantReadError and SSLWantWriteError to do just that.

Note: there is also some mention about calling SSLSocket.recv() to drain potentially available data before blocking on select(), but it seems like this is already covered by 3bd885ad8b88c146a466d1ac6494304032aff429 (relevant discussion: #48).

This would also fix #87.