# fatal error: all goroutines are asleep - deadlock! (RWMutex reader waiting on writer)

- **ID:** `go/deadlock-rwmutex-reader-writer`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A reader holds RLock and tries to acquire Lock, or a recursive RLock blocks because a pending writer is queued.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   Never upgrade RLock to Lock; release the read lock before acquiring the write lock:

mu.RUnlock()
mu.Lock()
defer mu.Unlock()
   ```
2. **** (88% success)
   ```
   Use a copy-on-write pattern with atomic.Pointer to avoid nested locks entirely.
   ```

## Dead Ends

- **** — Eliminates read concurrency but the nested-lock logic still deadlocks under the same call path. (80% fail)
- **** — The pending writer still blocks new readers; sleep merely reorders the deadlock. (85% fail)
