{
  "id": "go/goroutine-slice-append-race",
  "signature": "fatal error: concurrent slice writes",
  "signature_zh": "致命错误：并发切片写入",
  "regex": "fatal\\ error:\\ concurrent\\ slice\\ writes",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Multiple goroutines append to the same slice without synchronization, causing a data race.",
  "root_cause_type": "generic",
  "root_cause_zh": "多个协程在没有同步的情况下追加到同一个切片，导致数据竞争。",
  "versions": [
    {
      "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": "Using a channel to serialize appends but not draining the channel properly.",
      "why_fails": "If channel is buffered and not drained, goroutines may block or deadlock.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Assuming append is atomic.",
      "why_fails": "append is not atomic; it may read and update the slice header concurrently, causing corruption.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use a mutex to protect slice appends.",
      "success_rate": 0.95,
      "how": "var mu sync.Mutex\nvar slice []int\n\nfunc appendValue(v int) {\n    mu.Lock()\n    slice = append(slice, v)\n    mu.Unlock()\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a channel to aggregate results from goroutines.",
      "success_rate": 0.9,
      "how": "ch := make(chan int, 100)\nfor i := 0; i < n; i++ {\n    go func() {\n        ch <- compute()\n    }()\n}\nvar results []int\nfor i := 0; i < n; i++ {\n    results = append(results, <-ch)\n}",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-11-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}