{
  "id": "go/waitgroup-reused-before-wait",
  "signature": "panic: sync: WaitGroup is reused before previous Wait has returned",
  "signature_zh": "panic: sync: 在上一次 Wait 返回前复用了 WaitGroup",
  "regex": "panic:\\ sync:\\ WaitGroup\\ is\\ reused\\ before\\ previous\\ Wait\\ has\\ returned",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Calling wg.Add() again while a previous wg.Wait() is still in progress. The runtime detects the concurrent reuse.",
  "root_cause_type": "generic",
  "root_cause_zh": "在上一次 wg.Wait() 仍在进行时再次调用 wg.Add()。运行时会检测到这种并发复用。",
  "versions": [
    {
      "version": "1.19",
      "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": "Timing-dependent; under load the Wait may still be in progress.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Couples unrelated batches and can deadlock when one batch never completes.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.94,
      "how": "var wg sync.WaitGroup\nwg.Add(len(items))\nfor _, it := range items { go func(i int){ defer wg.Done(); process(i) }(it) }\nwg.Wait()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "done := make(chan struct{})\ngo func(){ wg.Wait(); close(done) }()\n<-done\n// safe to reuse",
      "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-05-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}