# starlette.websockets.WebSocketDisconnect: 1000

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

## Root Cause

Client closed the WebSocket; the handler keeps calling receive/send without catching the disconnect, propagating the exception.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (93% success)
   ```
   Catch and break:
try:
    while True:
        data = await ws.receive_text()
except WebSocketDisconnect:
    pass
   ```
2. **** (85% success)
   ```
   Use ws.iter_text() which stops on disconnect.
   ```

## Dead Ends

- **** — Loop keeps iterating after disconnect and raises again. (80% fail)
- **** — WebSocketDisconnect subclasses Exception but should break the loop, not just log. (65% fail)
