Giter Site home page Giter Site logo

Comments (6)

andrewgodwin avatar andrewgodwin commented on May 16, 2024 2

Released in 0.13.1.

from daphne.

andrewgodwin avatar andrewgodwin commented on May 16, 2024

Could you provide a way to reproduce, preferably using curl? Usually leaving off the Upgrade header results in a 200 OK, and the error you've posted a stack trace for looks like the __init__ hasn't been run, which is... odd.

from daphne.

quinox avatar quinox commented on May 16, 2024

I'm happy to debug this further so let me know what I can do. To be explicit: This happens when nginx isn't configured with the Upgrade-header-settings; in both cases the curl command is identical and does contain the Upgrade-header.


I can reproduce it with this minimal setup:

Terminal 1

$ mkdir /tmp/channels
$ cd /tmp/channels
$ virtualenv --python /usr/bin/python3 virtual
$ . virtual/bin/activate
$ pip install django channels asgi_redis
$ django-admin startproject testing  
$ vim testing/testing/settings.py  
[add channels to INSTALLED_APPS + CHANNEL_LAYERS, SEE BOTTOM]

$ vim testing/asgi.py
[ADD asgi.py, SEE BOTTOM]

$ vim testing/testing/routing.py
[EMTPY ROUTES, SEE BOTTOM]

$ vim /etc/nginx/sites-enabled/mysite.conf  
[SEE BOTTOM]

$ cd testing  
$ PYTHONOPTIMIZE=1 daphne -p 16661 asgi:channel_layer  

Terminal 2

experience@reaper:~$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H 'Sec-WebSocket-Version: 13'  -H 'Sec-WebSocket-Key: XXX==' -H "Host: experience.ytec.nl" -H "Origin: http://www.websocket.org" 'http://experience.ytec.nl/websocket/'
HTTP/1.1 502 Bad Gateway
Server: nginx/1.4.6 (Ubuntu)
Date: Mon, 27 Jun 2016 21:36:18 GMT
Content-Type: text/html
Content-Length: 181
Connection: keep-alive

<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.4.6 (Ubuntu)</center>
</body>
</html>

(That is Daphne crashing)

Terminal 1

^C
$ vim /tmp/channels/virtual/lib/python3.4/site-packages/dhne/http_protocol.py +107
[comment log line out]
$ PYTHONOPTIMIZE=1 daphne -p 16661 asgi:channel_layer

Terminal 2

experience@reaper:~$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H 'Sec-WebSocket-Version: 13'  -H 'Sec-WebSocket-Key: XXX==' -H "Host: experience.ytec.nl" -H "Origin: http://www.websocket.org" 'http://experience.ytec.nl/websocket/'
HTTP/1.1 400 HTTP Connection headers do not include 'upgrade' value (case-insensitive) : close
Server: nginx/1.4.6 (Ubuntu)
Date: Mon, 27 Jun 2016 21:37:33 GMT
Transfer-Encoding: chunked
Connection: keep-alive

testing/testing/settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'channels',
]

CHANNEL_LAYERS = {
    'default': {
        'ROUTING': 'testing.routing.channel_routing',
        'BACKEND': 'asgi_redis.RedisChannelLayer',
        'CONFIG': {
            'hosts': [('localhost', 6379)],
        }
    }
}

testing/asgi.py:

import os
from channels.asgi import get_channel_layer

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'testing.settings')

assert not __debug__ #Make sure the server is configured for not running in debug mode. Just enable optimization to set __debug__ to false.

channel_layer = get_channel_layer()

testing/routing.py:

channel_routing = []

/etc/nginx/sites-enabled/mysite.conf:

server {
    listen 80;
    server_name experience.ytec.nl;

    location /websocket/ {
        proxy_pass http://localhost:16661;

        proxy_http_version 1.1;
        proxy_buffering off;  
        proxy_set_header upgrade $http_upgrade;
        #proxy_set_header Connection "upgrade";
    }
}

from daphne.

andrewgodwin avatar andrewgodwin commented on May 16, 2024

Thanks for the curl command - running it directly against daphne also helped reproduce the error, as it had a bad Key which went down the same path.

I've pushed a fix to master; if you could confirm it works, I'll make a release.

from daphne.

quinox avatar quinox commented on May 16, 2024

It works like a charm.

from daphne.

alastairparagas avatar alastairparagas commented on May 16, 2024

I have the same problem as well. Tested the fix, seems good.

from daphne.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.