AlexStocks commented on code in PR #3231:
URL: https://github.com/apache/dubbo-go/pull/3231#discussion_r2899092435
##########
protocol/grpc/server.go:
##########
@@ -243,6 +198,14 @@ func registerService(providerServices
map[string]*global.ServiceConfig, server *
if invoker == nil {
panic(fmt.Sprintf("no invoker found for servicekey:
%v", serviceKey))
}
+ service, ok :=
invoker.GetURL().GetAttribute(constant.RpcServiceKey)
+ if !ok {
+ panic(fmt.Sprintf("no rpc service found in url
attribute %s for servicekey: %v", constant.RpcServiceKey, serviceKey))
+ }
+ ds, ok := service.(DubboGrpcService)
+ if !ok {
+ panic("illegal service type registered")
+ }
ds.SetProxyImpl(invoker)
server.RegisterService(ds.ServiceDesc(), service)
Review Comment:
类型断言 `ds, ok := service.(DubboGrpcService)` 已经得到了 `ds`,但最终传给
`server.RegisterService` 的仍是 `service`(类型 `any`)而非 `ds`。gRPC 的
`RegisterService` 需要第二个参数满足 service descriptor handler 签名,传 `any`
类型不一定满足,运行时可能失败。原代码传的是经过 `config.GetProviderService(key)` 拿到的具体对象,类型一致性有保障。
建议改为:
```go
server.RegisterService(ds.ServiceDesc(), ds)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]