{
  "id": "go/negative-waitgroup-counter",
  "signature": "panic: sync: negative WaitGroup counter",
  "signature_zh": "恐慌：sync：负的 WaitGroup 计数器",
  "regex": "panic:\\ sync:\\ negative\\ WaitGroup\\ counter",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Calling Done() more times than Add() was called, decrementing counter below zero.",
  "root_cause_type": "generic",
  "root_cause_zh": "调用 Done() 的次数多于 Add() 的次数，导致计数器减到负数。",
  "versions": [
    {
      "version": "1.0",
      "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": "Increasing Add() count arbitrarily",
      "why_fails": "If Done() is called extra times, the counter still goes negative.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignoring the panic and continuing",
      "why_fails": "Panic stops execution; ignoring it is not possible.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure Add() is called exactly once per goroutine that will call Done()",
      "success_rate": 0.95,
      "how": "var wg sync.WaitGroup\nfor i := 0; i < n; i++ {\n    wg.Add(1)\n    go func() { defer wg.Done(); work() }()\n}\nwg.Wait()",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use defer wg.Done() immediately after wg.Add() in the goroutine",
      "success_rate": 0.9,
      "how": "go func() { defer wg.Done(); ... }()",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}