{
  "id": "go/fatal-error-concurrent-map-writes",
  "signature": "fatal error: concurrent map writes",
  "signature_zh": "致命错误：并发映射写入",
  "regex": "fatal error: concurrent map writes",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Multiple goroutines are writing to the same map without synchronization, triggering Go's runtime race detector.",
  "root_cause_type": "generic",
  "root_cause_zh": "多个 goroutine 在没有同步的情况下写入同一个映射，触发了 Go 运行时的竞态检测器。",
  "versions": [
    {
      "version": "go1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Use a map with a mutex but lock only for writes, not reads",
      "why_fails": "Reads without locking can still cause data races and panic",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Replace map with sync.Map without understanding its semantics",
      "why_fails": "sync.Map is optimized for specific patterns (append-only, write-once); misuse can be slower or incorrect",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignore the error and rely on -race flag to catch it later",
      "why_fails": "The error is fatal and crashes the program immediately; cannot be ignored",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Protect the map with a sync.RWMutex: var mu sync.RWMutex; mu.Lock(); m[key] = value; mu.Unlock()",
      "success_rate": 0.94,
      "how": "Protect the map with a sync.RWMutex: var mu sync.RWMutex; mu.Lock(); m[key] = value; mu.Unlock()",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use sync.Map for concurrent access: var m sync.Map; m.Store(key, value); value, ok := m.Load(key)",
      "success_rate": 0.92,
      "how": "Use sync.Map for concurrent access: var m sync.Map; m.Store(key, value); value, ok := m.Load(key)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Restructure code to use a single goroutine that owns the map and communicates via channels",
      "success_rate": 0.9,
      "how": "Restructure code to use a single goroutine that owns the map and communicates via channels",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "使用 sync.RWMutex 保护映射：var mu sync.RWMutex; mu.Lock(); m[key] = value; mu.Unlock()",
    "使用 sync.Map 进行并发访问：var m sync.Map; m.Store(key, value); value, ok := m.Load(key)",
    "重构代码，使用单个 goroutine 拥有映射并通过通道进行通信"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://go.dev/doc/articles/race_detector",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.94,
  "resolvable": "true",
  "first_seen": "2023-02-28",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}