# error: sql: connection returned from pool was closed by the server

- **ID:** `go/database-sql-conn-max-lifetime-exceeded`
- **Domain:** go
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The database server closed the connection due to idle timeout, but the connection pool returned it as still valid.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.20 | active | — | — |
| 1.21 | active | — | — |

## Workarounds

1. **Set ConnMaxLifetime to less than server's wait_timeout** (90% success)
   ```
   db.SetConnMaxLifetime(5 * time.Minute)
db.SetMaxIdleConns(10)
   ```

## Dead Ends

- **Setting ConnMaxLifetime too high** — Long-lived connections may be closed by server anyway; need to match server timeout. (60% fail)
