{
  "id": "go/waitgroup-misused-copy",
  "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 called again while another goroutine is still in wg.Wait. Typically happens with a loop that reuses the same WaitGroup across iterations without resetting.",
  "root_cause_type": "generic",
  "root_cause_zh": "在另一个 goroutine 仍处于 wg.Wait 时再次调用 wg.Add。通常发生在循环中跨迭代复用同一个 WaitGroup 而未重置。",
  "versions": [
    {
      "version": "1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.23",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Reassigning while Wait is in flight races on the struct; still panics or corrupts state.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Sleep does not synchronize with Wait's completion; race remains.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "for _, batch := range batches {\n    var wg sync.WaitGroup\n    for _, x := range batch {\n        wg.Add(1)\n        go func(x int) { defer wg.Done(); work(x) }(x)\n    }\n    wg.Wait()\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.93,
      "how": "for _, batch := range batches {\n    g := new(errgroup.Group)\n    for _, x := range batch { x := x; g.Go(func() error { return work(x) }) }\n    if err := g.Wait(); err != nil { return err }\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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-21",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}