{
  "id": "go/concurrent-map-write-during-range",
  "signature": "fatal error: concurrent map iteration and map write",
  "signature_zh": "fatal error: 并发 map 迭代与 map 写入",
  "regex": "fatal\\ error:\\ concurrent\\ map\\ iteration\\ and\\ map\\ write",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A map is being range-iterated in one goroutine while another goroutine writes to the same map, violating Go's map safety rules.",
  "root_cause_type": "generic",
  "root_cause_zh": "一个 goroutine 正在 range 遍历 map，同时另一个 goroutine 写入同一个 map，违反了 Go 的 map 安全规则。",
  "versions": [
    {
      "version": "1.18",
      "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"
    },
    {
      "version": "1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Timing-based avoidance is unreliable; the runtime can still detect concurrent access under load.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This is a fatal runtime error, not a panic; recover cannot catch it and the process exits.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.97,
      "how": "var mu sync.RWMutex\nmu.RLock()\nfor k, v := range m { _ = k; _ = v }\nmu.RUnlock()\n// writer:\nmu.Lock()\nm[k] = v\nmu.Unlock()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "var m sync.Map\nm.Range(func(k, v any) bool { return true })\nm.Store(key, val)",
      "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": []
}