{
  "id": "go/goroutine-panic-unhandled",
  "signature": "panic: runtime error: invalid memory address or nil pointer dereference (in goroutine)",
  "signature_zh": "恐慌：运行时错误：无效的内存地址或空指针解引用（在 goroutine 中）",
  "regex": "panic:\\ runtime\\ error:\\ invalid\\ memory\\ address\\ or\\ nil\\ pointer\\ dereference\\ \\(in\\ goroutine\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A nil pointer dereference occurs inside a goroutine, causing a panic that is not recovered. This can happen when a goroutine accesses a nil pointer without checking.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 goroutine 内部发生空指针解引用，导致未恢复的恐慌。当 goroutine 未经检查就访问空指针时，可能会发生这种情况。",
  "versions": [
    {
      "version": "1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding a recover in the main goroutine only",
      "why_fails": "recover() only works within the same goroutine; panics in other goroutines cannot be recovered from the main goroutine.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignoring the panic and hoping the program continues",
      "why_fails": "An unhandled panic in any goroutine crashes the entire program.",
      "fail_rate": 0.99,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add a deferred recover inside the goroutine",
      "success_rate": 0.9,
      "how": "go func() {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Printf(\"Recovered in goroutine: %v\", r)\n        }\n    }()\n    // code that may panic\n    var p *int\n    *p = 42 // nil pointer dereference\n}()",
      "condition": "",
      "sources": []
    },
    {
      "action": "Check for nil pointers before dereferencing",
      "success_rate": 0.95,
      "how": "if p != nil {\n    *p = 42\n} else {\n    log.Println(\"nil pointer\")\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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-08-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}