# starlette.websockets.WebSocketDisconnect: 1006

- **ID:** `python/fastapi-websocket-disconnect-loop`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Client closed the socket without a close frame; server loop keeps calling receive/send without catching WebSocketDisconnect.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 0.100+ | active | — | — |
| 0.110+ | active | — | — |

## Workarounds

1. **** (93% success)
   ```
   try:
    while True:
        msg = await ws.receive_text()
        await ws.send_text(msg)
except WebSocketDisconnect:
    pass
   ```
2. **** (88% success)
   ```
   Use ws.iter_text() and break on disconnect; send a ping interval for liveness.
   ```

## Dead Ends

- **** — Hides real errors and leaks sockets; CPU spins on reconnect storms. (70% fail)
- **** — close() on a dead socket raises again. (75% fail)
