# sql: connection is already in use

- **ID:** `go/database-sql-conn-already-in-use`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A database connection was returned to the pool while still being used by another goroutine, causing a race condition.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.16 | active | — | — |
| 1.19 | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Ensure each query uses its own connection properly: use db.QueryContext with a context and avoid sharing rows between goroutines.
   ```
2. **** (75% success)
   ```
   Use a mutex to serialize access to rows: var mu sync.Mutex; mu.Lock(); defer mu.Unlock(); rows.Scan(...)
   ```

## Dead Ends

- **** — May cause data corruption or panics due to concurrent access. (80% fail)
- **** — Doesn't fix the root cause; may delay the issue but not prevent it. (50% fail)
