{
  "id": "go/waitgroup-reuse-before-wait",
  "signature": "panic: sync: WaitGroup is reused before previous Wait has returned",
  "signature_zh": "panic: sync: WaitGroup 在之前的 Wait 返回前被重用",
  "regex": "panic:\\ sync:\\ WaitGroup\\ is\\ reused\\ before\\ previous\\ Wait\\ has\\ returned",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "wg.Add is called again before a prior wg.Wait has returned, indicating the WaitGroup is being reused concurrently.",
  "root_cause_type": "generic",
  "root_cause_zh": "在上一次 wg.Wait 返回之前又调用了 wg.Add，说明 WaitGroup 被并发重用。",
  "versions": [
    {
      "version": "1.0+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Sleep cannot guarantee goroutine completion and reintroduces races.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Reassigning wg while goroutines hold a reference to the old one causes Done to target the wrong counter.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.94,
      "how": "for _, batch := range batches {\n    var wg sync.WaitGroup\n    for _, item := range batch {\n        wg.Add(1)\n        go func(i Item) { defer wg.Done(); work(i) }(item)\n    }\n    wg.Wait()\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "g := new(errgroup.Group)\nfor _, item := range batch {\n    g.Go(func() error { return work(item) })\n}\ng.Wait()",
      "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-12-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}