Daphne does not handle wss requests

338 views
Skip to first unread message

Giovanni Colapinto

unread,
Feb 23, 2017, 6:59:21 AM2/23/17
to Django users
Hi.

Before open a bug, could you please tell me if my setup is ok?

Daphne 1.0.3
channels 1.0.3

routing.py
channel_routing = [
route("websocket.connect", ws_connect, path=r"^/ws/chat/$"),
route("websocket.connect", ws_connect_updates, path=r"^/ws/updates/$"),
route("websocket.receive", ws_message_updates, path=r"^/ws/updates/$"),
route("websocket.disconnect", ws_disconnect),
route("http.request", http_ping, path=r"^/ping$", method=r"^GET$"),
]


channels worker started with:
manage.py runworker -v2

daphne started with:
daphne -e ssl:8003:privateKey=/etc/haproxy/keyring/spy.key:certKey=/etc/haproxy/keyring/spy.cert -v2 spywebsockets.asgi:channel_layer

No load balancer between client and sevrer (it's a dev env)

Client:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>WebSocket Client</title>
</head>
<body>

<script src="jquery.js"></script>
<script src="reconnecting-websocket.js"></script>
<script>
$(function () {
var wsUrl = "wss://127.0.0.1:8003/ws/updates/";
console.log("Connecting to " + wsUrl);
var socket = new ReconnectingWebSocket(wsUrl);
});
</script>
</body>
</html>

Error in firefox console:
11:54:03.682 Connecting to wss://127.0.0.1:8003/ws/updates/  websocket_client.html:14:9
11:54:05.686 Firefox can’t establish a connection to the server at wss://127.0.0.1:8003/ws/updates/.  reconnecting-websocket.js:213:17
11:54:05.687 The connection to wss://127.0.0.1:8003/ws/updates/ was interrupted while the page was loading.

Logs in daphne console:
ssh://ubu...@127.0.0.1:2222/opt/venv/spywebsockets/bin/python -u /opt/venv/spywebsockets/bin/daphne -e ssl:8003:privateKey=/etc/haproxy/keyring/spy.key:certKey=/etc/haproxy/keyring/spy.cert --proxy-headers -v2 spywebsockets.asgi:channel_layer
2017-02-23 11:42:02,875 INFO     Starting server at ssl:8003:privateKey=/etc/haproxy/keyring/spy.key:certKey=/etc/haproxy/keyring/spy.cert, channel layer spywebsockets.asgi:channel_layer.
2017-02-23 11:42:02,877 INFO     Using busy-loop synchronous mode on channel layer
2017-02-23 11:42:02,877 INFO     Listening on endpoint ssl:8003:privateKey=/etc/haproxy/keyring/spy.key:certKey=/etc/haproxy/keyring/spy.cert
2017-02-23 11:42:02,883 INFO     HTTPFactory (TLS) starting on 8003
2017-02-23 11:42:02,883 INFO     Starting factory <daphne.http_protocol.HTTPFactory object at 0x7f0a34a72b38>

It seems that daphne never handles the connection. If I restart daphne on the same port, but without ssl and change from wss to ws, all is fine (so no firewall issue)

Thanks,
Giovanni








Andrew Godwin

unread,
Feb 23, 2017, 1:15:44 PM2/23/17
to django...@googlegroups.com
It looks correct - can you connect using https://127.0.0.1:8003/ at that point either? It's really odd that apparently the connection doesn't even happen at all.

Andrew

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f45f593d-b8db-4cc4-af10-4fbf1dc3e953%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Giovanni Colapinto

unread,
Feb 24, 2017, 3:06:37 AM2/24/17
to Django users
Yep, it works


ssh://ubu...@127.0.0.1:2222/opt/venv/spywebsockets/bin/python -u /opt/venv/spywebsockets/bin/daphne -e ssl:8003:privateKey=/etc/haproxy/keyring/spy.key:certKey=/etc/haproxy/keyring/spy.cert --proxy-headers -v2 spywebsockets.asgi:channel_layer
2017-02-24 09:05:00,246 INFO     Starting server at ssl:8003:privateKey=/etc/haproxy/keyring/spy.key:certKey=/etc/haproxy/keyring/spy.cert, channel layer spywebsockets.asgi:channel_layer.
2017-02-24 09:05:00,247 INFO     Using busy-loop synchronous mode on channel layer
2017-02-24 09:05:00,248 INFO     Listening on endpoint ssl:8003:privateKey=/etc/haproxy/keyring/spy.key:certKey=/etc/haproxy/keyring/spy.cert
2017-02-24 09:05:00,255 INFO     HTTPFactory (TLS) starting on 8003
2017-02-24 09:05:00,255 INFO     Starting factory <daphne.http_protocol.HTTPFactory object at 0x7f31700d7b38>
2017-02-24 09:05:25,569 DEBUG    HTTP b'GET' request for http.response!QuVbbdTGYkgg
2017-02-24 09:05:25,747 DEBUG    HTTP 400 response started for http.response!QuVbbdTGYkgg
2017-02-24 09:05:25,748 DEBUG    HTTP close for http.response!QuVbbdTGYkgg
2017-02-24 09:05:25,752 INFO     "10.0.2.2" - - [24/Feb/2017:08:05:25 +0000] "GET / HTTP/1.1" 400 57606 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0"
2017-02-24 09:05:25,753 DEBUG    HTTP response complete for http.response!QuVbbdTGYkgg
10.0.2.2:1048 - - [24/Feb/2017:09:05:25] "GET /" 400 57606
2017-02-24 09:05:26,051 DEBUG    HTTP b'GET' request for http.response!GAGdgGoUEFHo
2017-02-24 09:05:26,141 DEBUG    HTTP 400 response started for http.response!GAGdgGoUEFHo
2017-02-24 09:05:26,143 DEBUG    HTTP close for http.response!GAGdgGoUEFHo
2017-02-24 09:05:26,143 INFO     "10.0.2.2" - - [24/Feb/2017:08:05:25 +0000] "GET /favicon.ico HTTP/1.1" 400 57588 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0"
2017-02-24 09:05:26,144 DEBUG    HTTP response complete for http.response!GAGdgGoUEFHo
10.0.2.2:1048 - - [24/Feb/2017:09:05:26] "GET /favicon.ico" 400 57588
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Andrew Godwin

unread,
Feb 24, 2017, 2:25:23 PM2/24/17
to django...@googlegroups.com
Hrm, I don't know what's happening then, something in your browser is stopping the connection before it even gets to Daphne. You'd have to break out Wireshark or something and look at what the packets on the wire were (and that's tough with TLS).

Anyone else have an idea what's happening?

Andrew

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

chris rose

unread,
Feb 24, 2017, 8:19:17 PM2/24/17
to Django users
I too experience this in my local development environment

I find secure web sockets throwing an error in the browser console when attempting to send a message:

InvalidStateError: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable.

I had attributed this to django being in debug mode, not serving secure http and thus not supporting secure ws

Giovanni Colapinto

unread,
Feb 25, 2017, 3:18:40 AM2/25/17
to Django users
Sadly it doesn't work, also with DEBUG=False
Reply all
Reply to author
Forward
0 new messages