{
  "id": "go/panic-sync-negative-waitgroup-counter",
  "signature": "panic: sync: negative WaitGroup counter",
  "signature_zh": "panic：sync：WaitGroup 计数器为负数",
  "regex": "panic:\\ sync:\\ negative\\ WaitGroup\\ counter",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "wg.Done() called more times than wg.Add(), typically from double-decrement or Done in a loop without matching Add.",
  "root_cause_type": "generic",
  "root_cause_zh": "wg.Done() 调用次数多于 wg.Add()，通常是重复减计数或循环中 Done 未匹配 Add。",
  "versions": [
    {
      "version": "1.0+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Panic is thrown inside sync.WaitGroup internal state; recover in the goroutine may catch it but leaves the counter corrupted.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Masks the bug; wg.Wait() then blocks forever because counter never reaches zero.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "wg.Add(1)\ngo func() {\n    defer wg.Done()\n    work()\n}()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "g, ctx := errgroup.WithContext(context.Background())\ng.Go(func() error { return work(ctx) })\nreturn g.Wait()",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-03",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}