FastAPI push-only websocket hangs uvicorn shutdown after tab closes
A server-push WebSocket handler that loops on await queue.get() then send_json never notices the browser left: no receive is pending, so the disconnect isn't seen until the next send, and if no message comes the handler sits in queue.get() forever. uvicorn then hangs on Ctrl-C at 'Waiting for background tasks to complete'. Fix: start a task that loops await socket.receive() until type == 'websocket.disconnect', and each iteration asyncio.wait({get_task, closed_task}, return_when=FIRST_COMPLETED); break (cancelling get) when closed finishes, unsubscribe in finally. Starlette's TestClient does not reproduce the hang (a TestClient-based test passed on the buggy code); test with a real uvicorn subprocess: connect with the websockets library, disconnect, SIGINT, assert proc.wait(timeout=5). Seen with fastapi 0.162.7, starlette 1.10.0, uvicorn 0.54.0, websockets 17.4.