{
  "id": "grpc/client-interceptor-panic-recovery",
  "signature": "INTERNAL: panic caught in unary client interceptor: runtime error: invalid memory address or nil pointer dereference",
  "signature_zh": "INTERNAL: 一元客户端拦截器中捕获到恐慌：运行时错误：无效内存地址或空指针解引用",
  "regex": "panic caught in (unary|stream) client interceptor: runtime error: invalid memory address or nil pointer dereference",
  "domain": "grpc",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A client-side interceptor panicked due to a nil pointer dereference, which was recovered by gRPC's internal recovery interceptor but not properly handled upstream.",
  "root_cause_type": "generic",
  "root_cause_zh": "客户端拦截器因空指针解引用而恐慌，被 gRPC 内部恢复拦截器捕获，但未在上游妥善处理。",
  "versions": [
    {
      "version": "gRPC-go v1.63.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "gRPC-java v1.62.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "envoy v1.29.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Restarting the client process without fixing the interceptor code will cause the same panic on the next request.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Adding a generic recovery handler at the application level that logs but returns a generic error masks the root cause, leading to silent data corruption.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Disabling all interceptors removes tracing and auth, but the underlying nil pointer might still exist in the call path.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add explicit nil checks before dereferencing context values in the interceptor. For example, in Go: if md, ok := metadata.FromIncomingContext(ctx); ok { ... } else { return nil, status.Error(codes.Internal, \"missing metadata\") }",
      "success_rate": 0.9,
      "how": "Add explicit nil checks before dereferencing context values in the interceptor. For example, in Go: if md, ok := metadata.FromIncomingContext(ctx); ok { ... } else { return nil, status.Error(codes.Internal, \"missing metadata\") }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Wrap the interceptor with a custom recovery middleware that converts panics to gRPC errors with stack traces: use grpc_recovery.UnaryServerInterceptor() from go-grpc-middleware.",
      "success_rate": 0.85,
      "how": "Wrap the interceptor with a custom recovery middleware that converts panics to gRPC errors with stack traces: use grpc_recovery.UnaryServerInterceptor() from go-grpc-middleware.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Upgrade to gRPC v1.64.0+ which includes improved panic recovery in interceptors, and enable verbose logging with GRPC_GO_LOG_SEVERITY_LEVEL=info to capture stack traces.",
      "success_rate": 0.75,
      "how": "Upgrade to gRPC v1.64.0+ which includes improved panic recovery in interceptors, and enable verbose logging with GRPC_GO_LOG_SEVERITY_LEVEL=info to capture stack traces.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Add explicit nil checks before dereferencing context values in the interceptor. For example, in Go: if md, ok := metadata.FromIncomingContext(ctx); ok { ... } else { return nil, status.Error(codes.Internal, \"missing metadata\") }",
    "Wrap the interceptor with a custom recovery middleware that converts panics to gRPC errors with stack traces: use grpc_recovery.UnaryServerInterceptor() from go-grpc-middleware.",
    "Upgrade to gRPC v1.64.0+ which includes improved panic recovery in interceptors, and enable verbose logging with GRPC_GO_LOG_SEVERITY_LEVEL=info to capture stack traces."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://github.com/grpc/grpc-go/blob/master/interceptor.go",
  "official_doc_section": null,
  "error_code": "GRPC_INTERNAL_PANIC_INTERCEPTOR",
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-03-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}