Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AX-Vlady-Vaysberg opened this issue Jun 6, 2018 · 7 comments

Comments

@AX-Vlady-Vaysberg
Copy link

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
Copy link

ghost commented Aug 13, 2018

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

@jrief
Copy link
Owner

jrief commented Aug 14, 2018

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

@jeffhaessler
Copy link

@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 (unbit/uwsgi#1899), as it's unclear to me how they intended for websockets to be closed from the client.

@oortega
Copy link

oortega commented Mar 5, 2020

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

@oortegawh
Copy link

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

@Ericwonne
Copy link

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

@bahmany
Copy link

bahmany commented Oct 26, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants