fastapi-socketio
fastapi-socketio copied to clipboard
Support for multiple workers?
I'm just wondering how to get multiple workers working with socketio (this might be an issue with python-socketio, but I'm not sure). I'm currently on 0.0.10 and have the kwargs support, so I've tried using a client_manager
like such:
from fastapi_socketio import SocketManager
from socketio import AsyncRedisManager
...
client_manager = AsyncRedisManager('redis://localhost:6379/1')
socket_manager = SocketManager(app=app, client_manager=client_manager)
and executing the server with
$ DEBUG=1 python -m uvicorn main:app --port 9000 --host 0.0.0.0 --workers 4
But when I attach a client to it, I've noticed that the client constantly disconnects and reconnects. In the server log, I'll get:
INFO: connection closed
INFO: 127.0.0.1:35020 - "POST /socket.io/?EIO=4&transport=polling&t=OjdZ_BE&sid=drxs24MybaAm66dEAAAF HTTP/1.1" 200 OK
INFO: 127.0.0.1:35034 - "GET /socket.io/?EIO=4&transport=polling&t=OjdZ_S3 HTTP/1.1" 200 OK
INFO: 127.0.0.1:35040 - "POST /socket.io/?EIO=4&transport=polling&t=OjdZ_SF&sid=Vfa5Ul5cdE23LNbpAAAD HTTP/1.1" 400 Bad Request
Invalid session Vfa5Ul5cdE23LNbpAAAD (further occurrences of this error will be logged with level INFO)
2023-10-25 08:59:30 kevin-ubuntu engineio.server[182810] ERROR Invalid session Vfa5Ul5cdE23LNbpAAAD (further occurrences of this error will be logged with level INFO)
INFO: 127.0.0.1:35056 - "GET /socket.io/?EIO=4&transport=polling&t=OjdZ_SH&sid=Vfa5Ul5cdE23LNbpAAAD HTTP/1.1" 400 Bad Request
INFO: ('127.0.0.1', 35066) - "WebSocket /socket.io/?EIO=4&transport=websocket&sid=Vfa5Ul5cdE23LNbpAAAD" [accepted]
INFO: connection open
INFO: connection closed
INFO: 127.0.0.1:35074 - "POST /socket.io/?EIO=4&transport=polling&t=OjdZ_SX&sid=Vfa5Ul5cdE23LNbpAAAD HTTP/1.1" 400 Bad Request
INFO: 127.0.0.1:35080 - "GET /socket.io/?EIO=4&transport=polling&t=OjdZ_gT HTTP/1.1" 200 OK
INFO: 127.0.0.1:35094 - "POST /socket.io/?EIO=4&transport=polling&t=OjdZ_gz&sid=Q3nKr2Uz_s2hrSFbAAAG HTTP/1.1" 400 Bad Request
INFO: 127.0.0.1:35116 - "GET /socket.io/?EIO=4&transport=polling&t=OjdZ_h0&sid=Q3nKr2Uz_s2hrSFbAAAG HTTP/1.1" 400 Bad Request
INFO: ('127.0.0.1', 35108) - "WebSocket /socket.io/?EIO=4&transport=websocket&sid=Q3nKr2Uz_s2hrSFbAAAG" 403
INFO: connection failed (403 Forbidden)
INFO: connection closed
INFO: 127.0.0.1:35122 - "POST /socket.io/?EIO=4&transport=polling&t=OjdZ_hG&sid=Q3nKr2Uz_s2hrSFbAAAG HTTP/1.1" 400 Bad Request
INFO: 127.0.0.1:35134 - "GET /socket.io/?EIO=4&transport=polling&t=OjdZ_ra HTTP/1.1" 200 OK
INFO: 127.0.0.1:35148 - "POST /socket.io/?EIO=4&transport=polling&t=OjdZ_sC&sid=zhul5vF4Rxl087nVAAAB HTTP/1.1" 400 Bad Request
INFO: 127.0.0.1:35150 - "GET /socket.io/?EIO=4&transport=polling&t=OjdZ_sF&sid=zhul5vF4Rxl087nVAAAB HTTP/1.1" 400 Bad Request
INFO: ('127.0.0.1', 35152) - "WebSocket /socket.io/?EIO=4&transport=websocket&sid=zhul5vF4Rxl087nVAAAB" 403
Similarly, on the client side, I'm seeing the connection drop due to the 403.
any updates on this?? I want to use gunicorn with multiple workers