# RuntimeError: Task exception was never retrieved
future: <Task finished ...> ... Error during lifespan startup

- **ID:** `python/starlette-lifespan-startup-error`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

An exception raised inside the lifespan startup handler prevents the ASGI server from fully starting.

## Version Compatibility

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

## Workarounds

1. **** (92% success)
   ```
   from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app):
    try:
        await init_db()
    except Exception:
        logger.exception('startup failed')
        raise
    yield
   ```
2. **** (88% success)
   ```
   for _ in range(5):
    try: await init_db(); break
    except Exception: await asyncio.sleep(2)
   ```

## Dead Ends

- **** — Skips DB connection and other required startup logic. (85% fail)
- **** — Server starts in a broken state with missing resources. (80% fail)
