From ae8ce0b4309fa62d5781b26754c6f7463c32e584 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Thu, 24 Jan 2019 02:47:50 -0500 Subject: [PATCH] Install gevent-websocket and use it by default until we have a better solution (#850) * Install `gevent-websocket` and use it by default until we have a better solution * May help with #849 --- CTFd/config.py | 6 +++--- docker-entrypoint.sh | 3 ++- requirements.txt | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CTFd/config.py b/CTFd/config.py index 1a443415..cab762db 100644 --- a/CTFd/config.py +++ b/CTFd/config.py @@ -209,8 +209,8 @@ class Config(object): Example: /ctfd SOCKETIO_ASYNC_MODE: - Specifies what async mode SocketIO should use. The simplest but least performant option is 'threading'. - Switching to a different async mode is not recommended without the appropriate load balancing mechanisms + Specifies what async mode SocketIO should use. + Specifying your own async mode is not recommended without the appropriate load balancing mechanisms in place and proper understanding of how websockets are supported by Flask. https://flask-socketio.readthedocs.io/en/latest/#deployment ''' @@ -219,7 +219,7 @@ class Config(object): SQLALCHEMY_TRACK_MODIFICATIONS = (not os.getenv("SQLALCHEMY_TRACK_MODIFICATIONS")) # Defaults True UPDATE_CHECK = (not os.getenv("UPDATE_CHECK")) # Defaults True APPLICATION_ROOT = os.getenv('APPLICATION_ROOT') or '/' - SOCKETIO_ASYNC_MODE = os.getenv('SOCKETIO_ASYNC_MODE') or 'threading' + SOCKETIO_ASYNC_MODE = os.getenv('SOCKETIO_ASYNC_MODE') ''' === OAUTH === diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index eaa885c6..fb739548 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -2,6 +2,7 @@ set -eo pipefail WORKERS=${WORKERS:-1} +WORKER_CLASS=${WORKER_CLASS:-geventwebsocket.gunicorn.workers.GeventWebSocketWorker} ACCESS_LOG=${ACCESS_LOG:--} ERROR_LOG=${ERROR_LOG:--} @@ -40,6 +41,6 @@ echo "Starting CTFd" exec gunicorn 'CTFd:create_app()' \ --bind '0.0.0.0:8000' \ --workers $WORKERS \ - --worker-class 'gevent' \ + --worker-class "$WORKER_CLASS" \ --access-logfile "$ACCESS_LOG" \ --error-logfile "$ERROR_LOG" diff --git a/requirements.txt b/requirements.txt index 97a44c7d..5efe95c0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,6 +20,7 @@ netaddr==0.7.19 redis==2.10.6 datafreeze==0.1.0 gevent==1.3.7 +gevent-websocket==0.10.1 python-dotenv==0.9.1 flask-restplus==0.12.1 pathlib2==2.3.2