{
  "id": "go/waitgroup-add-positive-delta",
  "signature": "panic: sync: negative WaitGroup counter",
  "signature_zh": "panic: WaitGroup 计数器为负",
  "regex": "panic:\\ sync:\\ negative\\ WaitGroup\\ counter",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "wg.Done() is called more times than wg.Add(). Usually a missing Add before launching a goroutine, a double defer wg.Done(), or Done called in a loop path that runs more than the added count.",
  "root_cause_type": "generic",
  "root_cause_zh": "wg.Done() 的调用次数多于 wg.Add()。通常是因为启动 goroutine 前漏了 Add、重复 defer wg.Done()，或 Done 在循环路径中执行次数超过 Add 的数量。",
  "versions": [
    {
      "version": "1.18",
      "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"
    },
    {
      "version": "1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Masks the real double-Done bug and can cause Wait to hang forever if the count never reaches zero.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Wait then blocks forever because the counter never decrements.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.96,
      "how": "wg.Add(1)\ngo func() {\n    defer wg.Done()\n    work()\n}()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "func launch(wg *sync.WaitGroup, f func()) {\n    wg.Add(1)\n    go func() { defer wg.Done(); f() }()\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-02-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}