AlexStocks commented on code in PR #3231:
URL: https://github.com/apache/dubbo-go/pull/3231#discussion_r2899091151


##########
protocol/grpc/client.go:
##########
@@ -142,25 +118,25 @@ func NewClient(url *common.URL) (*Client, error) {
        }
 
        key := url.GetParam(constant.InterfaceKey, "")
-       //TODO: Temporary compatibility with old APIs, can be removed later
-       consumerService := config.GetConsumerServiceByInterfaceName(key)
-       if consumerService == nil {
-               if rpcService, ok := url.GetAttribute(constant.RpcServiceKey); 
ok {
-                       consumerService = rpcService
-               }
+       var consumerService any
+       if rpcService, ok := url.GetAttribute(constant.RpcServiceKey); ok {
+               consumerService = rpcService
        }
        invoker := getInvoker(consumerService, conn)

Review Comment:
   `getInvoker` 内部:`reflect.ValueOf(nil).MethodByName("GetDubboStub")` 当 
`consumerService` 为 nil 时会直接 **panic**,根本不会返回 nil 供调用方检查。`if invoker != nil` 这个 
nil guard 加在 panic 之后,毫无意义。另外返回 `reflect.Value{}` 后续调用 `invoker.Call(...)` 同样会 
panic。
   
   建议:在调用 `getInvoker` 前检查:
   ```go
   if consumerService == nil {
       conn.Close()
       return nil, fmt.Errorf("grpc: no rpc service found for interface=%s", 
key)
   }
   ```



-- 
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]

Reply via email to