{
  "id": "go/deadlock-mutex-double-lock",
  "signature": "fatal error: all goroutines are asleep - deadlock!\ngoroutine 1 [sync.Mutex.Lock]:",
  "signature_zh": "致命错误：所有 goroutine 处于休眠状态 - 死锁！\ngoroutine 1 [sync.Mutex.Lock]：",
  "regex": "fatal\\ error:\\ all\\ goroutines\\ are\\ asleep\\ \\-\\ deadlock!\\\ngoroutine\\ 1\\ \\[sync\\.Mutex\\.Lock\\]:",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A goroutine locks a sync.Mutex twice without unlocking in between, or two goroutines acquire two mutexes in opposite order. The runtime detects a full stop.",
  "root_cause_type": "generic",
  "root_cause_zh": "一个 goroutine 在未解锁的情况下两次锁定同一个 sync.Mutex，或两个 goroutine 以相反顺序获取两个互斥锁。运行时检测到完全停止。",
  "versions": [
    {
      "version": "1.0+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "sync.Mutex has no timeout API; you must restructure the code or use a channel-based lock.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "All runnable goroutines are blocked on the mutex; more Ps do not help.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.96,
      "how": "func (s *Service) Do() {\n    s.mu.Lock()\n    defer s.mu.Unlock()\n    // ...\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.93,
      "how": "// Always lock A before B\nfunc transfer(a, b *Account) {\n    if a.id < b.id { a.mu.Lock(); b.mu.Lock() } else { b.mu.Lock(); a.mu.Lock() }\n    defer a.mu.Unlock(); defer b.mu.Unlock()\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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-27",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}