{
  "id": "go/goroutine-sync-pool-race",
  "signature": "WARNING: DATA RACE: Write by goroutine X, Read by goroutine Y (sync.Pool)",
  "signature_zh": "警告：数据竞争：协程X写入，协程Y读取（sync.Pool）",
  "regex": "WARNING:\\ DATA\\ RACE:\\ Write\\ by\\ goroutine\\ X,\\ Read\\ by\\ goroutine\\ Y\\ \\(sync\\.Pool\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Using sync.Pool without proper understanding; objects in pool may be accessed concurrently without synchronization.",
  "root_cause_type": "generic",
  "root_cause_zh": "未正确理解sync.Pool的使用；池中的对象可能在没有同步的情况下被并发访问。",
  "versions": [
    {
      "version": "1.3",
      "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 sync.Pool provides synchronization",
      "why_fails": "sync.Pool does not synchronize access to pooled objects; only the pool itself is safe.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using global variables instead of pool",
      "why_fails": "Global variables are shared; race condition persists.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure pooled objects are not shared between goroutines",
      "success_rate": 0.85,
      "how": "pool := &sync.Pool{New: func() interface{} { return &MyStruct{} }}\ngo func() {\n    obj := pool.Get().(*MyStruct)\n    // use obj exclusively\n    pool.Put(obj)\n}()",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use mutex inside pooled object if sharing is needed",
      "success_rate": 0.8,
      "how": "type MyStruct struct {\n    mu sync.Mutex\n    data int\n}\nobj := pool.Get().(*MyStruct)\nobj.mu.Lock()\nobj.data = 42\nobj.mu.Unlock()\npool.Put(obj)",
      "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.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-09-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}