jrief / django-websocket-redis

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

Websocket closing errors out in Django 1.11 #238

Closed erikreed closed 7 years ago

erikreed commented 7 years ago

Responsible snippet (wsgi_server.py:148):

logger.warning('WebSocketError: {}'.format(excpt), exc_info=sys.exc_info())
response = http.HttpResponse(status=1001, content='Websocket Closed')

Stack trace:

Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/ws4redis/uwsgi_runserver.py", line 28, in receive
return uwsgi.websocket_recv_nb()
OSError: unable to receive websocket message
WARNING:django.request:WebSocketError: unable to receive websocket message
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/ws4redis/wsgi_server.py", line 131, in __call__
recvmsg = RedisMessage(websocket.receive())
File "/usr/local/lib/python3.6/dist-packages/ws4redis/uwsgi_runserver.py", line 31, in receive
raise WebSocketError(e)
ws4redis.exceptions.WebSocketError: unable to receive websocket message
ValueError: HTTP status code must be an integer from 100 to 599.
File "/usr/local/lib/python3.6/dist-packages/ws4redis/uwsgi_runserver.py", line 28, in receive

The cause is HTTP status code validation added in Django v1.11: https://github.com/django/django/commit/190d2ff4a7a392adfe0b12552bd71871791d87aa

i.e. 100 <= self.status_code <= 599.

dmorina commented 6 years ago

@jrief sorry if this is documented somewhere and i missed it, but this issue still persists raise ValueError('HTTP status code must be an integer from 100 to 599.') (Django==1.11.3) and i see that this status code is still 1001 in the main branch https://github.com/jrief/django-websocket-redis/blob/a830aa792874b78a76aeb21baf7c4b554e554dfd/ws4redis/wsgi_server.py#L151

Is there a reason for it being a non standard HTTP response code? Thanks!

jrief commented 6 years ago

From my understanding at that time, this was the correct Websocket HTTP code. Shall it be changed?

dmorina commented 6 years ago

Argh, I’m still running 0.4.7 in that environment, thought I’m using the latest version, should work just fine after upgrading. Thanks!! If django continues adding validations to the HttpResponseBase class we might have to move away from using HttpResponse to be able to use websocket status codes. Right now they are only checking on init