# asyncio.TimeoutError: WebSocket receive timed out

- **ID:** `python/starlette-websocket-timeout`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A WebSocket receive operation exceeds the configured timeout period.

## Version Compatibility

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

## Workarounds

1. **Use asyncio.wait_for with a reasonable timeout** (90% success)
   ```
   try:
    data = await asyncio.wait_for(websocket.receive_text(), timeout=10)
except asyncio.TimeoutError:
    await websocket.close(code=1000)
   ```
2. **Set timeout in the WebSocket endpoint configuration** (85% success)
   ```
   from starlette.websockets import WebSocketEndpoint
class MyEndpoint(WebSocketEndpoint):
    receive_timeout = 30
   ```

## Dead Ends

- **Increasing timeout to an extremely high value** — May cause resource exhaustion; not a real fix. (60% fail)
- **Ignoring the timeout and retrying indefinitely** — Leads to infinite loop and resource leak. (85% fail)
