{
  "id": "go/panic-sync-waitgroup-reused-before-wait",
  "signature": "panic: sync: WaitGroup is reused before previous Wait has returned",
  "signature_zh": "恐慌：sync: WaitGroup 在之前 Wait 返回前被重用",
  "regex": "panic:\\ sync:\\ WaitGroup\\ is\\ reused\\ before\\ previous\\ Wait\\ has\\ returned",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "WaitGroup.Add() is called after Wait() has started but before it returns, violating the rule that Add must not be called concurrently with Wait.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 Wait() 开始但尚未返回时调用了 WaitGroup.Add()，违反了 Add 不能与 Wait 并发的规则。",
  "versions": [
    {
      "version": "1.18",
      "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": "",
      "why_fails": "Sleep does not guarantee Wait has returned; race still possible.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If batches overlap, the same issue can occur; requires careful lifecycle management.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Ensure all Add calls happen before any Wait call. Use a single WaitGroup per logical group and don't reuse until Wait returns.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "Use errgroup.Group which manages lifecycle safely:\ng, ctx := errgroup.WithContext(ctx)\nfor ... { g.Go(...) }\nreturn g.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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-08-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}