jrief / django-websocket-redis

Websockets for Django applications using Redis as message queue
http://django-websocket-redis.awesto.com/
MIT License
895 stars 221 forks source link

WebSocketError: unable to receive websocket message on regular websocket closing with uwsgi #266

Open AX-Vlady-Vaysberg opened 6 years ago

AX-Vlady-Vaysberg commented 6 years ago

Hey everyone,

So on closing a regular websocket i get no errors while using the "django manage.py runserver" dev server. But when using uwsgi i get some api and js errors on closing a websocket with 'ws.close()'. Everything works as expected in both cases. Its only that this error messages do spam quite a bit.

JS (Chrome): WebSocket connection to 'ws://localhost:8000/api_ws/apis/ax/v1/inventory/job/?subscribe-broadcast' failed: One or more reserved bits are on: reserved1 = 1, reserved2 = 0, reserved3 = 1

API(Django==1.11.13): WebSocketError: unable to receive websocket message Traceback (most recent call last): File "pyenv3/lib/python3.6/site-packages/ws4redis/uwsgi_runserver.py", line 28, in receive return uwsgi.websocket_recv_nb()

OSError: unable to receive websocket message During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "pyenv3/lib/python3.6/site-packages/ws4redis/wsgi_server.py", line 131, in __call__ recvmsg = RedisMessage(websocket.receive()) File "pyenv3/lib/python3.6/site-packages/ws4redis/uwsgi_runserver.py", line 31, in receive raise WebSocketError(e) ws4redis.exceptions.WebSocketError: unable to receive websocket message [pid: 41342|app: 0|req: 1/27] 127.0.0.1 () {48 vars in 3558 bytes} [Wed Jun 6 09:03:42 2018] GET /api_ws/apis/ax/v1/inventory/job/?subscribe-broadcast => generated 84 bytes in 6974 msecs (HTTP/1.1 101) 4 headers in 184 bytes (3 switches on core 99)

After some playing around with the code in the file 'uwsgi_runserver.py' and commenting out line 31 i got both errors fixed.

uwsgi_runserver.py: 24 def receive(self): 25 if self._closed: 26 raise WebSocketError("Connection is already closed") 27 try: 28 return uwsgi.websocket_recv_nb() 29 except IOError as e: 30 self.close() 31 # raise WebSocketError(e)

Does anyone else experience this problem? Any other solutions? Why is this happening on closing a regular websocket connection? Any help would be greatly appreciated :)

ghost commented 5 years ago

have you resolve this problem? if you do, please tell me, thank you

jrief commented 5 years ago

@leonard-chen Currently, I unfortunately have no free unpaid time to improve this project.

jeffhaessler commented 5 years ago

@jrief first of all thank you for your work on this project - been happily using it in production for 2 years now.

I have this same issue, and it was also noted in #255.

Basically what's happening is receive() gets called before close(). uwsgi then throws a fit when it tries to websocket_recv_nb() the close message.

I've also raised an issue with the uwsgi team (https://github.com/unbit/uwsgi/issues/1899), as it's unclear to me how they intended for websockets to be closed from the client.

oortega commented 4 years ago

@AX-Vlady-Vaysberg can you please tell me if you resolve this issue?. Thanks

oortegawh commented 3 years ago

I have the same problem, use gevent==1.4.0 with gevent==20.6.2 I have problems

Ericwonne commented 3 years ago

Me seeing this error too. Doesn't actually impact the system, but logs aren't pretty

bahmany commented 2 years ago

I had the problem, too, and after different investigations I found that my redis server had a problem and it solved my problem by installing redis again.