{
  "id": "go/goroutine-mutex-deadlock",
  "signature": "fatal error: all goroutines are asleep - deadlock! (mutex)",
  "signature_zh": "致命错误：所有协程都处于休眠状态 - 死锁！（互斥锁）",
  "regex": "fatal\\ error:\\ all\\ goroutines\\ are\\ asleep\\ \\-\\ deadlock!\\ \\(mutex\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Two or more goroutines hold locks and wait for each other to release them, causing a circular wait condition.",
  "root_cause_type": "generic",
  "root_cause_zh": "两个或多个协程持有锁并等待彼此释放，导致循环等待条件。",
  "versions": [
    {
      "version": "1.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.19",
      "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.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Use a single global mutex",
      "why_fails": "A single mutex can cause contention but not deadlock if used correctly; however, if nested locks are needed, it can still deadlock.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignore the deadlock and restart the program",
      "why_fails": "Temporary fix; the deadlock will recur.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Always lock mutexes in the same order",
      "success_rate": 0.95,
      "how": "// Lock mu1 then mu2 consistently\nmu1.Lock()\nmu2.Lock()\n// unlock in reverse order",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use trylock with a fallback",
      "success_rate": 0.8,
      "how": "if mu.TryLock() {\n    defer mu.Unlock()\n    // critical section\n} else {\n    // handle contention\n}",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}