{
  "id": "go/goroutine-timer-channel-leak",
  "signature": "fatal error: runtime: out of memory (timer channel leak)",
  "signature_zh": "致命错误：运行时：内存不足（定时器通道泄漏）",
  "regex": "fatal\\ error:\\ runtime:\\ out\\ of\\ memory\\ \\(timer\\ channel\\ leak\\)",
  "domain": "go",
  "category": "resource_error",
  "subcategory": null,
  "root_cause": "Creating many time.Timer or time.Ticker without stopping them, causing goroutine and channel leaks that exhaust memory.",
  "root_cause_type": "generic",
  "root_cause_zh": "创建大量 time.Timer 或 time.Ticker 而不停止它们，导致协程和通道泄漏，耗尽内存。",
  "versions": [
    {
      "version": "1.20",
      "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": "Using time.After in a loop without resetting.",
      "why_fails": "Each call to time.After creates a new timer; if not stopped, they accumulate.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Assuming timers are garbage collected after firing.",
      "why_fails": "Timers are not GC'd until they fire or are stopped; if not stopped, they remain in memory.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Always stop timers after use with defer.",
      "success_rate": 0.95,
      "how": "timer := time.NewTimer(1 * time.Second)\ndefer timer.Stop()\nselect {\ncase <-timer.C:\n    // do something\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use time.NewTicker and stop it when done.",
      "success_rate": 0.9,
      "how": "ticker := time.NewTicker(1 * time.Second)\ndefer ticker.Stop()\nfor range ticker.C {\n    // periodic work\n    if condition {\n        break\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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-01-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}