Open ladyisatis opened 3 months ago
I think this must be an issue with Hypercorn. When running with Uvicorn the Socket.IO connection is properly canceled. This is how I'm testing it:
if __name__ == '__main__':
uvicorn.run(ASGIApp(socketio, fastapi_app), host='127.0.0.1', port=3005)
Interesting! I'll try and fiddle around with converting the program I had back to Uvicorn, as something odd was going on with Pyinstaller and Windows support so I'd switched to the other alternative I could find. (I dunno if you want me to close this issue and raise the lock issue with the Hypercorn folks instead, but up to you!)
Using FastAPI and python-socketio/python-engineio in conjunction with Hypercorn in Asyncio mode, if you CTRL+C or send SIGINT/SIGTERM (no matter on Windows or Linux) the Python script will never exit and
socketio.shutdown()
will not do anything until all clients are disconnected from the client-side, and then shutdown scripts will proceed. There's no way to detect this from lifespan functions for example,To reproduce, main.py:
html/index.html:
And then put
socket.io.min.js
inside thehtml/assets
folder. Then:python3 main.py
python3 main.py