{
  "id": "go/goroutine-count-explosion",
  "signature": "fatal error: out of memory allocating heap arena metadata",
  "signature_zh": "致命错误：分配堆区域元数据时内存不足",
  "regex": "fatal\\ error:\\ out\\ of\\ memory\\ allocating\\ heap\\ arena\\ metadata",
  "domain": "go",
  "category": "resource_error",
  "subcategory": null,
  "root_cause": "Unbounded go statement per incoming request or per item spawns millions of goroutines, exhausting memory.",
  "root_cause_type": "generic",
  "root_cause_zh": "对每个传入请求或每个条目无限制地使用 go 语句，生成数百万个 goroutine，耗尽内存。",
  "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"
    },
    {
      "version": "1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Goroutine stacks dominate memory; GC tuning does not reduce goroutine count.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "GOMEMLIMIT forces GC but goroutines keep spawning; OOM still occurs or throughput collapses.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "sem := make(chan struct{}, 100)\nfor _, item := range items {\n    sem <- struct{}{}\n    go func(it Item) {\n        defer func() { <-sem }()\n        process(it)\n    }(item)\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.93,
      "how": "jobs := make(chan Job, 1000)\nfor i := 0; i < runtime.NumCPU(); i++ {\n    go func() {\n        for j := range jobs { process(j) }\n    }()\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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-08-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}