0
votes

Heyo,

I am trying to create websocket server using flask-socketio but I ran into a problem, the sockets drop! I am running gunicorn with 4 workers and I am aware of the fact that socketio library is storing the data in-memory(that is why I have redis installed because I have encountered similar issue before), I have pointed an app to the redis server but it still doesn't work with 4 workers, however running gunicorn with 1 worker is okay.

Here is my application init code:

from flask import Flask
from flask_json import FlaskJSON, JsonError, json_response, as_json
from webroutes import shallow
from userapi import user_api
from app_service import shallow_service
import os
from flask_socketio import SocketIO
from reddissession import RedisSessionInterface
from socket_worker import Messenger
import eventlet
eventlet.monkey_patch()
# from gevent.wsgi import WSGIServer

application = Flask(__name__)
application.secret_key = os.urandom(64)
FlaskJSON(application)
socketio = SocketIO()
socketio.on_namespace(Messenger("/messenger_socket"));
application.register_blueprint(shallow)
application.register_blueprint(user_api)
application.register_blueprint(shallow_service)
application.config['TEMPLATES_AUTO_RELOAD'] = True


application.session_interface = RedisSessionInterface()
socketio.init_app(application, message_queue='redis://')

Here is what I get in console.log:

Output

Please send help, thanks

1

1 Answers