Open tf198 opened 7 months ago
Managed to get something that shuts down cleanly, including raising asicio.CancelledError
on active connections
https://github.com/tf198/quart/commit/a6a9ec1e5bdaa4d5e410b4150fa95b5d870af262
Not sure if it the most elegant solution but async messes with my head!
Also looking for a solution to this in the main branch. When dockerized, my app will not stop running if a socketio conneciton is open until I refresh the client to make the connection go away. Then it terminates.
I have the same issue and have not found a good way to handle this yet.
I have the same issue with HTTP streaming as opposed to websockets.
Edit: This seems to really be an issue in Hypercorn — the blocking happens in hypercorn.asyncio.run.worker_serve()
when it calls await server.wait_closed()
. I managed to handle it, at the cost of some verbosity, by
asyncio.Event
as shutdown_trigger
when calling hypercorn.asyncio.serve()
serve()
, setting up a signal handler to trigger that event:
for sig in (signal.SIGINT, signal.SIGTERM):
asyncio.get_running_loop().add_signal_handler(sig, aborting.set)
I have the same problem and it started showing up after switching to python 3.12. After rolling back to 3.11 everything works fine.
Using the minimal example websocket code the quart server hangs on CTRL+C until all clients have closed their connections. This also applies to SSE examples.
app.py
client.py
The server should be closing all open websockets on SIGINT and allow the errors to propagate for cleanup.
I've been unable to find a nice solution to this. Currently manually adding a SIGINT handler to the current asyncio loop and calling
loop.close()
but that doesn't allow for nice cleanup.Environment: