{
  "id": "go/goroutine-waitgroup-wait-in-loop",
  "signature": "panic: sync: WaitGroup is reused before previous Wait has returned",
  "signature_zh": "恐慌：同步：WaitGroup在之前的Wait返回之前被重用",
  "regex": "panic:\\ sync:\\ WaitGroup\\ is\\ reused\\ before\\ previous\\ Wait\\ has\\ returned",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Calling Add() on a WaitGroup while a previous Wait() is still in progress, causing race.",
  "root_cause_type": "generic",
  "root_cause_zh": "在之前的Wait()仍在进行时对WaitGroup调用Add()，导致竞态条件。",
  "versions": [
    {
      "version": "1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.20",
      "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 in this context; program crashes.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding more Done() calls to unblock Wait",
      "why_fails": "Counter imbalance causes negative counter panic.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Create a new 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 channels to synchronize instead of reusing WaitGroup",
      "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": "2024-12-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}