{
  "id": "go/fatal-error-concurrent-map-iteration-and-map-write",
  "signature": "fatal error: concurrent map iteration and map write",
  "signature_zh": "fatal error: 并发遍历 map 并写入",
  "regex": "fatal\\ error:\\ concurrent\\ map\\ iteration\\ and\\ map\\ write",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "One goroutine ranges over a map while another goroutine writes to it, which the runtime detects and aborts.",
  "root_cause_type": "generic",
  "root_cause_zh": "一个 goroutine 正在 range 遍历 map，同时另一个 goroutine 写入该 map，运行时检测到并中止。",
  "versions": [
    {
      "version": "1.18",
      "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": "The copy itself races with the writer; the runtime aborts during the copy loop.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Maps have no index operator; this does not compile, and even an equivalent iteration still races.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "Hold a sync.RWMutex: mu.RLock(); for k, v := range m { ... }; mu.RUnlock(), and mu.Lock() for writes.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Snapshot under lock: mu.RLock(); snapshot := make(map[K]V, len(m)); for k, v := range m { snapshot[k] = v }; mu.RUnlock(); then range over snapshot.",
      "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-06-18",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}