# fatal error: sync: unlock of unlocked mutex

- **ID:** `go/fatal-error-sync-unlock-of-unlocked-mutex`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

mu.Unlock() is called when the mutex is not held, usually because a defer unlock runs after an early return or a double unlock.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   Use defer mu.Unlock() immediately after mu.Lock() in the same function so they always pair.
   ```
2. **** (90% success)
   ```
   Audit all code paths: ensure no early return between Lock and Unlock without defer, and never unlock in a different function than the one that locked.
   ```

## Dead Ends

- **** — This is a fatal runtime error, not a panic; recover cannot catch it and the process exits. (98% fail)
- **** — The flag itself needs synchronization and is often set incorrectly, reintroducing the bug under concurrency. (80% fail)
