go
runtime_error
ai_generated
true
rpc error: code = Unknown desc = 运行时错误:无效的内存地址或空指针解引用
rpc error: code = Unknown desc = runtime error: invalid memory address or nil pointer dereference
ID: go/grpc-unknown-non-status-error
80%修复率
88%置信度
0证据数
2025-04-18首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
根因分析
服务端处理程序发生 panic。gRPC 恢复 panic 并返回 Unknown,但 panic 消息泄漏到错误描述中。真正的根因是处理程序中的空指针解引用。
English
The server handler panicked. gRPC recovers the panic and returns Unknown, but the panic message leaks into the error description. The real cause is a nil pointer dereference in the handler.
解决方案
-
90% 成功率
func recovery(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { defer func() { if r := recover(); r != nil { log.Printf("panic in %s: %v\n%s", info.FullMethod, r, debug.Stack()) } }() return handler(ctx, req) } -
95% 成功率
if req == nil || req.User == nil { return nil, status.Error(codes.InvalidArgument, "user is required") }
无效尝试
常见但无效的做法:
-
90% 失败
The server will panic again for the same input; retries just amplify load and log noise
-
95% 失败
The panic happened on the server; client-side recover cannot catch it