# asyncio.CancelledError: Task was cancelled during StreamingResponse iteration

- **ID:** `python/starlette-sse-client-disconnect`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

An SSE StreamingResponse generator kept yielding after the client disconnected; the ASGI server cancelled the task.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 0.30+ | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   async def gen(request: Request):
    while True:
        if await request.is_disconnected():
            break
        yield f'data: {tick()}\n\n'
        await asyncio.sleep(1)
   ```
2. **** (85% success)
   ```
   async def gen():
    try:
        while True:
            yield data
            await asyncio.sleep(1)
    finally:
        cleanup()
   ```

## Dead Ends

- **** — The connection is gone; yield raises again and the task leaks. (85% fail)
- **** — Clients still close tabs; cancellation is normal, not preventable. (70% fail)
