django-websocket-redis icon indicating copy to clipboard operation
django-websocket-redis copied to clipboard

Werzeug incompatibility

Open michela opened this issue 11 years ago • 4 comments

Can't get Werkzeug to run cleanly with this, websocket connection keeps breaking when running ./manage.py runserver_plus

Werkzeug==0.9.6 django-extensions==1.3.8 django-websocket-redis==0.4.1

[2014-07-29 22:04:57,421 django_runserver] DEBUG: WebSocket request accepted, switching protocols [2014-07-29 22:04:57,422 wsgi_server] ERROR: Other Exception: Traceback (most recent call last): File "/mnt/hgfs/conversation-server/ws4redis/wsgi_server.py", line 72, in __call__ websocket = self.upgrade_websocket(environ, start_response) File "/mnt/hgfs/conversation-server/ws4redis/django_runserver.py", line 56, in upgrade_websocket six.get_method_self(start_response).finish_content() AttributeError: 'function' object has no attribute 'im_self' [2014-07-29 22:04:57,424 wsgi_server] INFO: Finish long living response with status code: 192.168.85.1 - - [29/Jul/2014 22:04:57] "GET /ws/foobar?subscribe-broadcast&publish-broadcast&echo HTTP/1.1" 101 -

michela avatar Jul 29 '14 12:07 michela

I never used werkzeug, so I can't really say whats the problem. You're encountering this problem in debug mode. There ws4redis hijacks the main loop if the URL starts with /ws. I assume that werkzeug somehow gets in conflict with this approach. Could you please dig into that direction.

jrief avatar Jul 29 '14 12:07 jrief

The problem is that werkzeug is using standard django WSGI handler from from django.core.handlers.wsgi import WSGIHandler, so if it's not overwritten then it fails. And I didn't found setting to do that without monkeypatching or editing source code.

It's working ok, but werkzeug is WSGI which isn't Async like websockets, so after keeping connection too long it just closing it forcefully. It event write you about it INFO: Finish long living response with status code: 192.168.85.1 - - [29/Jul/2014 22:04:57] "GET /ws/foobar?subscribe-broadcast&publish-broadcast&echo HTTP/1.1" 101

It's just incompatible. Use django-devserver witch allow to add option --wsgi-app=ws4redis.django_runserver or add such possibility to werkzeug :)

kosz85 avatar Aug 15 '14 12:08 kosz85

@kosz85 were you able to successfully monkey-patch Werkzeug then?

szelga avatar Sep 08 '14 14:09 szelga

No I'm just using django-devserver. I think it's easier and less time consuming to use nginx with uwsgi or django-devserver then rewriting werkzeug. If this is not an option, you can try run two separate servers, one for websockets without werkzeug and second normal for django app with werkzeug. Thought such setup will need to add some changes to app (adding port for websockets or proxy like nginx).

kosz85 avatar Sep 08 '14 14:09 kosz85