{
  "id": "go/mutex-copied-after-use",
  "signature": "panic: sync: mutex is locked",
  "signature_zh": "恐慌：sync：互斥锁已被锁定",
  "regex": "panic:\\ sync:\\ mutex\\ is\\ locked",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A sync.Mutex or other sync primitive is copied after use, causing the lock state to be duplicated and leading to deadlock or panic when the copy is used.",
  "root_cause_type": "generic",
  "root_cause_zh": "sync.Mutex 或其他同步原语在使用后被复制，导致锁状态被复制，使用副本时可能导致死锁或恐慌。",
  "versions": [
    {
      "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": "",
      "why_fails": "The panic will recur unpredictably; it's a fundamental design flaw.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Copying a mutex is illegal; it cannot be safely copied at all.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.98,
      "how": "type SafeCounter struct {\n    mu sync.Mutex\n    v  int\n}\n\nfunc (c *SafeCounter) Inc() {\n    c.mu.Lock()\n    c.v++\n    c.mu.Unlock()\n}\n\n// Always use *SafeCounter, never copy the struct.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "type Counter struct {\n    mu *sync.Mutex\n    v  int\n}\n\nfunc NewCounter() *Counter {\n    return &Counter{mu: &sync.Mutex{}}\n}\n\nfunc (c *Counter) Inc() {\n    c.mu.Lock()\n    c.v++\n    c.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.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}