{
  "id": "go/racy-map-access",
  "signature": "fatal error: concurrent map iteration and map write",
  "signature_zh": "致命错误：并发 map 迭代和 map 写入",
  "regex": "fatal\\ error:\\ concurrent\\ map\\ iteration\\ and\\ map\\ write",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "One goroutine is iterating over a map while another goroutine writes to it, causing a race condition.",
  "root_cause_type": "generic",
  "root_cause_zh": "一个 goroutine 正在迭代 map，而另一个 goroutine 正在写入该 map，导致竞态条件。",
  "versions": [
    {
      "version": "1.6",
      "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 sync.Mutex only around writes",
      "why_fails": "Iteration also needs protection; concurrent iteration and write still race.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using a RWMutex for reads but not for iteration",
      "why_fails": "Iteration is a read operation but may still race with writes if not locked.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use sync.RWMutex to protect both reads and writes",
      "success_rate": 0.95,
      "how": "var mu sync.RWMutex\nmu.RLock()\nfor k, v := range myMap { ... }\nmu.RUnlock()\nmu.Lock()\nmyMap[key] = value\nmu.Unlock()",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use sync.Map for concurrent-safe map operations",
      "success_rate": 0.9,
      "how": "var m sync.Map\nm.Store(key, value)\nm.Load(key)",
      "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-10-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}