miguelgrinberg / Flask-SocketIO

Socket.IO integration for Flask applications.
MIT License
5.37k stars 892 forks source link

Messages correctly parsed with Chromium but not in Firefox #1745

Closed jvinolas closed 2 years ago

jvinolas commented 2 years ago

We are receving some strange websocket messages that does'nt seem to be handled correctly in Firefox (but correctly by Chromium). The message throws a JSON.parse error at Firefox:

000}42/isard-admin/sio_admins,["s_da_quota",accesse {\"d1638480197.al"4613": 0active{\"dtrue": 0category{\"d": efaul, \": 0email{\"d":sio_a@}42/i.io \": 0group{\"d": efaul,- efaul, \": 0id{\"d":local- efaul,sard-asard-a \": 0name{\"d":Ard-aistrator \": 0photo{\"d": \": 0provider{\"d":local \": 0ser_q{\"dfalse": 0role{\"d":sio_a \": 0table{\"d":s,["s \": 0uid{\"d":sio_a \": 0s,["name{\"d":sio_a \": 0vpnobal\":iptablesobales": 0wiregu2/iobal\":Address{\"d":10.0.0.2 \": 0AllowedIPs{\"d":10.2.0.0/16 \": 0connecte {\"dtrue": 0extra_client_nets{\"dnull}": 1

As you can see it starts with an strange 000} and also the dictionary keys and values have some characters added/modified. I've added logs in python to see what is being send with json.dumps and all seem to be correct.

The thing is that some events arrive well and others not, but only fails to be decoded by Firefox, not in Chromium, as you can see with both clients connected and receiving the same events:

imatge

The library versions used are:

python-socketio==5.5.0
python-engineio==4.3.0
Flask-SocketIO==5.1.0
eventlet==0.31.0

And the js client socketio tested are 4.1.3 and 4.4.0, with same behaviour.

The app is starting multiple threads that can send events and worked well till now. Any hints on what can be the cause of the randomly bad formatted messages received?

miguelgrinberg commented 2 years ago

worked well till now

What changed when the problem started? This package doesn't really do anything low-level regarding WebSocket, it just uses the facilities provided by the underlying implementation, which I assume in this case is eventlet. So if there is a problem related to corruption of WS packets, it could be something there that causes it.

jvinolas commented 2 years ago

I'll focus on eventlet and try to see what is happening. Thanks!

jvinolas commented 2 years ago

Indeed it was eventlet, wireshark at server side showed that the message was coming out in incorrect format. I upgraded from 0.31 to 0.33 and this bug disappeared.

antmatyjajo commented 2 years ago

Had this same problem with incomplete/mangled/corrupt messages arriving in Firefox - upgrading from eventlet 0.26.1 to 0.33 seems to have solved the issue.