# sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) SSL connection has been closed unexpectedly

- **ID:** `python/sqlalchemy-connection-pool-recycle`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Database server closed idle connections due to timeout; pool still holds stale connections.

## Version Compatibility

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

## Workarounds

1. **Set pool_recycle to a value less than server idle timeout.** (95% success)
   ```
   engine = create_engine(url, pool_recycle=3600)  # Recycle connections every hour
   ```
2. **Enable pool_pre_ping to check connection health.** (90% success)
   ```
   engine = create_engine(url, pool_pre_ping=True)
   ```

## Dead Ends

- **Disabling SSL entirely.** — Security risk; may not be allowed by policy. (50% fail)
- **Increasing pool_timeout.** — Does not refresh stale connections. (70% fail)
