# fatal error: sync: Unlock of unlocked mutex

- **ID:** `go/goroutine-mutex-not-unlocked`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Calling Unlock on a mutex that wasn't locked by the same goroutine, often due to missing Lock or double Unlock.

## Version Compatibility

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

## Workarounds

1. **Use defer to ensure Unlock is called exactly once after Lock** (99% success)
   ```
   mu.Lock()
defer mu.Unlock()
// critical section
   ```
2. **Use sync.Mutex with proper pairing in all code paths** (90% success)
   ```
   mu.Lock()
if condition {
    mu.Unlock()
    return
}
mu.Unlock()
   ```

## Dead Ends

- **Using recover() to catch panic** — Panic is fatal and cannot be recovered in Go runtime; program crashes. (100% fail)
- **Adding more Unlock calls to match Lock** — Double unlock causes panic; correct pairing is required. (90% fail)
