{
  "id": "go/mutex-unlock-of-unlocked-mutex",
  "signature": "fatal error: sync: unlock of unlocked mutex",
  "signature_zh": "致命错误：sync：解锁未加锁的 mutex",
  "regex": "fatal\\ error:\\ sync:\\ unlock\\ of\\ unlocked\\ mutex",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Unlock() is called on a sync.Mutex that is not currently locked, usually from a deferred Unlock on an error path where Lock was never reached.",
  "root_cause_type": "generic",
  "root_cause_zh": "对一个当前未加锁的 sync.Mutex 调用 Unlock()，通常是在未执行 Lock 的错误路径上执行了 defer Unlock。",
  "versions": [
    {
      "version": "1.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The mutex state is inconsistent; subsequent Lock calls may deadlock or panic unpredictably.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "RWMutex has the same Unlock semantics, so the bug persists.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "mu.Lock()\ndefer mu.Unlock()\n// critical section",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "func lock(mu *sync.Mutex) func() {\n    mu.Lock()\n    return mu.Unlock\n}\nunlock := lock(&mu)\ndefer unlock()",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}