{
  "id": "go/goroutine-racy-close-waitgroup",
  "signature": "panic: sync: WaitGroup is reused before previous Wait has returned (racy close)",
  "signature_zh": "恐慌：同步：WaitGroup在之前的Wait返回之前被重用（竞争关闭）",
  "regex": "panic:\\ sync:\\ WaitGroup\\ is\\ reused\\ before\\ previous\\ Wait\\ has\\ returned\\ \\(racy\\ close\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Calling WaitGroup.Wait() and then Add() concurrently from multiple goroutines.",
  "root_cause_type": "generic",
  "root_cause_zh": "从多个协程并发调用WaitGroup.Wait()然后Add()。",
  "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 recover() to catch panic",
      "why_fails": "Panic is unrecoverable; program crashes.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding time.Sleep between Wait and Add",
      "why_fails": "Race condition still exists; timing-dependent.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use separate WaitGroup for each batch",
      "success_rate": 0.95,
      "how": "for batch := 0; batch < 3; batch++ {\n    var wg sync.WaitGroup\n    for i := 0; i < 5; i++ {\n        wg.Add(1)\n        go func() { defer wg.Done(); /* work */ }()\n    }\n    wg.Wait()\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use channel-based synchronization",
      "success_rate": 0.85,
      "how": "ch := make(chan struct{})\nfor i := 0; i < 5; i++ {\n    go func() { /* work */; ch <- struct{}{} }()\n}\nfor i := 0; i < 5; i++ {\n    <-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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2026-05-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}