{
  "id": "go/nil-pointer-deref-goroutine",
  "signature": "panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV] (in goroutine N)",
  "signature_zh": "panic: 运行时错误：无效内存地址或 nil 指针解引用 [signal SIGSEGV]（在 goroutine N 中）",
  "regex": "panic:\\ runtime\\ error:\\ invalid\\ memory\\ address\\ or\\ nil\\ pointer\\ dereference\\ \\[signal\\ SIGSEGV\\]\\ \\(in\\ goroutine\\ N\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A goroutine dereferences a nil pointer, commonly a struct field or interface left uninitialized before the goroutine starts.",
  "root_cause_type": "generic",
  "root_cause_zh": "goroutine 解引用了 nil 指针，通常是 goroutine 启动前未初始化的结构体字段或接口。",
  "versions": [
    {
      "version": "1.18",
      "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": "The nil deref indicates a logic bug; swallowing it leaves the goroutine's work incomplete and can corrupt state.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Hides diagnostics; the crash still terminates the program.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Initialize all pointers before spawning the goroutine and prefer value receivers:\n\ncfg := &Config{}\ngo worker(cfg) // cfg is non-nil",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "Add nil guards at goroutine entry and return early with an error:\n\nif s == nil {\n    return errors.New(\"nil service\")\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-10-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}