{
  "id": "go/goroutine-racy-channel-send-recv",
  "signature": "WARNING: DATA RACE: Write by goroutine X, Read by goroutine Y (channel send/recv)",
  "signature_zh": "警告：数据竞争：协程X写入，协程Y读取（通道发送/接收）",
  "regex": "WARNING:\\ DATA\\ RACE:\\ Write\\ by\\ goroutine\\ X,\\ Read\\ by\\ goroutine\\ Y\\ \\(channel\\ send/recv\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Sending a pointer to a struct via channel, then modifying the struct in sender while receiver reads it.",
  "root_cause_type": "generic",
  "root_cause_zh": "通过通道发送结构体指针，然后发送者在接收者读取时修改结构体。",
  "versions": [
    {
      "version": "1.0",
      "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Assuming channel synchronization protects the data",
      "why_fails": "Channel synchronizes the send/recv operation, not the data pointed to.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Copying pointer before send",
      "why_fails": "Copying pointer doesn't deep copy the struct; still shared.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Send value instead of pointer",
      "success_rate": 0.95,
      "how": "ch := make(chan MyStruct)\ngo func() {\n    s := MyStruct{Field: 42}\n    ch <- s // copy of s\n}()\ns := <-ch",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use mutex to protect shared struct",
      "success_rate": 0.85,
      "how": "type Shared struct {\n    mu sync.Mutex\n    data MyStruct\n}\nvar s Shared\nch := make(chan *Shared)\ngo func() {\n    s.mu.Lock()\n    s.data.Field = 42\n    s.mu.Unlock()\n    ch <- &s\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": "2026-06-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}