# RuntimeError: Connection does not exist.

- **ID:** `python/starlette-runtimeerror-connection-does-not-exist`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Attempting to use a WebSocket connection that has already been closed or was never established.

## Version Compatibility

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

## Workarounds

1. **Check if WebSocket is connected before using** (85% success)
   ```
   if websocket.client_state == starlette.websockets.WebSocketState.CONNECTED:
    await websocket.send_text('hello')
   ```
2. **Handle disconnection with try-except** (90% success)
   ```
   try:
    await websocket.receive_text()
except RuntimeError:
    # connection closed
    pass
   ```

## Dead Ends

- **Reusing WebSocket object after disconnect** — WebSocket connections are single-use; must accept new connections. (80% fail)
- **Assuming connection persists across requests** — Each WebSocket request creates a new connection object. (90% fail)
