{
  "id": "go/waitgroup-wait-reused",
  "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": "wg.Add() is called to reuse a WaitGroup while a prior wg.Wait() has not yet returned. The runtime detects the counter being reused and panics to prevent silent miscounting.",
  "root_cause_type": "generic",
  "root_cause_zh": "在之前的 wg.Wait() 尚未返回时调用 wg.Add() 复用 WaitGroup。运行时检测到计数器被复用并 panic，以防静默计数错误。",
  "versions": [
    {
      "version": "1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The reuse still happens concurrently; the panic is about ordering, not the calling goroutine.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Copying a WaitGroup that has been used is unsafe and may race with the in-flight Wait.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use a fresh WaitGroup per batch instead of reusing:\nvar wg sync.WaitGroup\nfor _, batch := range batches {\n    wg = sync.WaitGroup{}\n    // Add/Go/Wait for this batch\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Ensure all goroutines have called Done before calling Add for the next round; synchronize rounds with a barrier channel.",
      "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-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}