dpallot / simple-websocket-server

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

Intermittent frame corruption #24

Closed hp685 closed 8 years ago

hp685 commented 8 years ago

I use this package in conjunction with websocket-client (https://pypi.python.org/pypi/websocket-client/) for the application. While running regressions on this application, intermittently, the client raises a WebSocketPayLoadException and on a closer look, it appears that the server is sending binary data in a text frame (possibly the control frame spills over into data frame?)

data = ws.recv()
File "/usr/local/lib/python2.7/site-packages/websocket_client-0.21.0-py2.7.egg/websocket/_core.py", line 667, in recv
opcode, data = self.recv_data()
File "/usr/local/lib/python2.7/site-packages/websocket_client-0.21.0-py2.7.egg/websocket/_core.py", line 684, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "/usr/local/lib/python2.7/site-packages/websocket_client-0.21.0-py2.7.egg/websocket/_core.py", line 724, in recv_data_frame
raise WebSocketPayloadException("cannot decode: " + repr(frame.data))
websocket._exceptions.WebSocketPayloadException: cannot decode: '\x81~\x01?'

I'm certain that the application doesn't inject any data since we use the same backend via a different channel.

dpallot commented 8 years ago

The send is not injecting any spurious packets and they are all being sent in order. Is your ws client doing a single read or does it deal with fragmented packets? Posting some code might help.

hp685 commented 8 years ago

I was using https://github.com/liris/websocket-client version 0.16 and upgrading it to version 0.34 seemed to have solved the issue. Frame validation has changed from the earlier version and I haven't spent time investigating where the problem lay.