{
  "id": "go/waitgroup-wait-race",
  "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": "A WaitGroup was reused (Add called) while a previous Wait() had not yet returned, which is explicitly disallowed by the sync package.",
  "root_cause_type": "generic",
  "root_cause_zh": "在上一轮 Wait() 尚未返回时就再次调用了 Add() 复用 WaitGroup，sync 包明确禁止这种用法。",
  "versions": [
    {
      "version": "1.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Recover leaves the WaitGroup in an inconsistent state and the concurrent Wait may return early or hang.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Two Waits on the same group do not resolve the reuse race; it can still panic.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Timing-based, non-deterministic, and fails under load.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "for _, batch := range batches {\n    var wg sync.WaitGroup\n    for _, it := range batch {\n        wg.Add(1)\n        go func(it Item) { defer wg.Done(); process(it) }(it)\n    }\n    wg.Wait()\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "for _, stage := range stages {\n    g := new(errgroup.Group)\n    for _, t := range stage { g.Go(t.Run) }\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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-08-09",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}