# asyncio.exceptions.InvalidStateError: Future is already resolved

- **ID:** `python/asyncio-future-invalid-state`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Attempting to set a result or exception on a Future that has already been resolved (completed or cancelled).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |

## Workarounds

1. **Check if the future is done before setting result** (90% success)
   ```
   if not future.done():
    future.set_result(value)
   ```
2. **Use asyncio.Future with proper lifecycle management** (85% success)
   ```
   future = asyncio.get_event_loop().create_future()
# ensure only one set_result call
   ```

## Dead Ends

- **Checking if the future is done before setting result** — If done, setting result is still invalid; this may cause the error if not handled properly. (50% fail)
- **Using a new Future for each operation** — This may lead to resource leaks if old futures are not cleaned up. (40% fail)
