{
  "id": "go/goroutine-http-server-race",
  "signature": "WARNING: DATA RACE: Write by goroutine X, Read by goroutine Y (http.Handler)",
  "signature_zh": "警告：数据竞争：协程X写入，协程Y读取（http.Handler）",
  "regex": "WARNING:\\ DATA\\ RACE:\\ Write\\ by\\ goroutine\\ X,\\ Read\\ by\\ goroutine\\ Y\\ \\(http\\.Handler\\)",
  "domain": "go",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "Multiple HTTP handler goroutines accessing shared state without synchronization.",
  "root_cause_type": "generic",
  "root_cause_zh": "多个HTTP处理程序协程在没有同步的情况下访问共享状态。",
  "versions": [
    {
      "version": "1.0",
      "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 global variables for request state",
      "why_fails": "Global variables are shared across all requests; race condition.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using request-scoped variables incorrectly",
      "why_fails": "If variable is captured by closure, it may be shared.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use local variables within handler",
      "success_rate": 0.95,
      "how": "http.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n    var counter int\n    counter++\n    fmt.Fprintf(w, \"%d\", counter)\n})",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use sync.Mutex for shared state",
      "success_rate": 0.9,
      "how": "var mu sync.Mutex\nvar counter int\nhttp.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n    mu.Lock()\n    counter++\n    mu.Unlock()\n    fmt.Fprintf(w, \"%d\", counter)\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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-11-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}