{
  "id": "go/goroutine-map-concurrent-read-and-write",
  "signature": "fatal error: concurrent map read and map write",
  "signature_zh": "致命错误：并发 map 读取和 map 写入",
  "regex": "fatal\\ error:\\ concurrent\\ map\\ read\\ and\\ map\\ write",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "One goroutine reads from a map while another writes to it without synchronization, causing a data race.",
  "root_cause_type": "generic",
  "root_cause_zh": "一个协程从 map 中读取，而另一个协程在没有同步的情况下写入 map，导致数据竞争。",
  "versions": [
    {
      "version": "1.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.19",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "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": "Use a read-write lock (sync.RWMutex) only for writes",
      "why_fails": "If reads are not protected, they can still race with writes.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a copy of the map for reads",
      "why_fails": "Copying a map while it is being written is unsafe and can cause a race.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use sync.RWMutex to protect both reads and writes",
      "success_rate": 0.95,
      "how": "var mu sync.RWMutex\nmu.RLock()\nval := myMap[key]\nmu.RUnlock()",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use sync.Map for concurrent read/write",
      "success_rate": 0.9,
      "how": "var m sync.Map\nm.Load(key) // safe concurrent read",
      "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-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}