{
  "id": "go/rwmutex-write-lock-deadlock",
  "signature": "fatal error: all goroutines are asleep - deadlock! (RWMutex write lock)",
  "signature_zh": "致命错误：所有 goroutine 都处于休眠状态 - 死锁！（RWMutex 写锁）",
  "regex": "fatal\\ error:\\ all\\ goroutines\\ are\\ asleep\\ \\-\\ deadlock!\\ \\(RWMutex\\ write\\ lock\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A goroutine holding a read lock tries to acquire a write lock, causing a deadlock because write lock waits for all read locks to release.",
  "root_cause_type": "generic",
  "root_cause_zh": "持有读锁的 goroutine 尝试获取写锁，导致死锁，因为写锁需要等待所有读锁释放。",
  "versions": [
    {
      "version": "1.0",
      "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": "Using a separate mutex for writes",
      "why_fails": "Does not address the recursive locking issue; may still deadlock.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Increasing the number of goroutines",
      "why_fails": "More goroutines can exacerbate the deadlock.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Avoid holding read lock when acquiring write lock; release read lock first",
      "success_rate": 0.95,
      "how": "rw.RUnlock()\nrw.Lock()\n// write\nrw.Unlock()\nrw.RLock() // if needed again",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a single mutex instead of RWMutex if write locks are frequent",
      "success_rate": 0.9,
      "how": "var mu sync.Mutex\nmu.Lock()\n// write\nmu.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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}