Skip to content

Instantly share code, notes, and snippets.

@ikatson
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikatson/9374163 to your computer and use it in GitHub Desktop.
Save ikatson/9374163 to your computer and use it in GitHub Desktop.
uwsgi + harakiri + websockets bug
<html>
<head>
<script>
var polling = (function () {
var poll_error_timeout = 1;
var default_error_timeout = poll_error_timeout + 0;
var poll_error_max_timeout = 15;
function pollForEventsWebsockets() {
var s = new WebSocket('ws://localhost:8000/ws');
var retry = function () {
console.log(
'retrying websocket connection in ' + poll_error_timeout);
setTimeout(pollForEventsWebsockets, poll_error_timeout * 1000);
poll_error_timeout = Math.min(
poll_error_max_timeout, poll_error_timeout * 2);
};
s.onopen = function() {
console.log("Websocket connected");
poll_error_timeout = default_error_timeout;
};
s.onmessage = function(e) {
console.log('Received message', e.data);
poll_error_timeout = default_error_timeout;
};
s.onerror = function(e) {
console.error(e);
};
s.onclose = function(e) {
console.log('ws connection closed');
retry();
};
}
pollForEventsWebsockets();
return {}
}());
</script>
</head>
<body>
</body>
</html>
[uwsgi]
master=true
harakiri=5
gevent=100
gevent-mokey=
http=127.0.0.1:8000
http-websockets=
post-buffering=
file=wsgi.py
home=/tmp/uwsgienv
# coding: utf-8
import logging
log = logging.getLogger(__name__)
def handle_websocket(environ, start_response):
import uwsgi
uwsgi.websocket_handshake()
uwsgi.websocket_recv()
def application(environ, start_response):
if environ['PATH_INFO'] == '/ws':
return handle_websocket(environ, start_response)
start_response('200', [('Content-Type', 'text/html')])
with open('index.html') as html:
return html.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment