tiangolo / fastapi

FastAPI framework, high performance, easy to learn, fast to code, ready for production
https://fastapi.tiangolo.com/
MIT License
73.13k stars 6.16k forks source link

Support for Websocket Ping to check connection status and clean up stale connections #11700

Closed TheNotary closed 3 weeks ago

TheNotary commented 3 weeks ago

Privileged issue

Issue Content

I just read #626, and it seems like handling ping was discussed and resolved, but nothing was mentioned around sending a ping out to a client. I believe that would test the connection and allow a WebsocketDiscconnect exception to be thrown allowing the connection to be cleaned up. It seems though that the websocket I'm referencing doesn't expose a .conn attribute so I don't understand how to send a ping. Could someone provide a more explicit explanation around invoking websocket ping from the server to validate connections?