# fatal error: sync: unlock of unlocked mutex

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

## Root Cause

Attempting to unlock a mutex that is not locked, often due to double unlock or unlocking in wrong goroutine.

## Version Compatibility

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

## Workarounds

1. **Always use defer to unlock immediately after lock** (95% success)
   ```
   mu.Lock()
defer mu.Unlock()
// critical section
   ```
2. **Ensure unlock is called exactly once per lock** (90% success)
   ```
   Use paired Lock/Unlock in same function; avoid manual unlock in error paths without defer.
   ```

## Dead Ends

- **Adding a flag to check if mutex is locked** — Mutex does not expose lock state; race conditions on the flag. (85% fail)
- **Using recover() to ignore the panic** — Recovering does not fix the logic error; may cause data corruption. (70% fail)
