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


##########
protocol/grpc/server.go:
##########
@@ -107,23 +104,9 @@ func (s *Server) Start(url *common.URL) {
                grpc.MaxSendMsgSize(maxServerSendMsgSize),
        )
 
-       // TODO: remove config TLSConfig
-       // delete this branch
-       tlsConfig := config.GetRootConfig().TLSConfig
-       if tlsConfig != nil {
-               var cfg *tls.Config
-               cfg, err = config.GetServerTlsConfig(&config.TLSConfig{
-                       CACertFile:    tlsConfig.CACertFile,
-                       TLSCertFile:   tlsConfig.TLSCertFile,
-                       TLSKeyFile:    tlsConfig.TLSKeyFile,
-                       TLSServerName: tlsConfig.TLSServerName,
-               })
-               if err != nil {
-                       return
-               }
-               logger.Infof("gRPC Server initialized the TLSConfig 
configuration")
-               serverOpts = append(serverOpts, 
grpc.Creds(credentials.NewTLS(cfg)))
-       } else if tlsConfRaw, ok := url.GetAttribute(constant.TLSConfigKey); ok 
{
+       var transportCreds credentials.TransportCredentials
+       transportCreds = insecure.NewCredentials()
+       if tlsConfRaw, ok := url.GetAttribute(constant.TLSConfigKey); ok {

Review Comment:
   `lis` 在函数开头 `net.Listen("tcp", addr)` 创建后,TLS 处理段有两个 `return` 路径(L114 
类型断言失败、L119 `GetServerTlSConfig` 出错)都不关闭 listener。
   
   导致 listener 既不被 `server.Serve(lis)` 消费,也不被 `Close()`,端口永久占用,后续重启绑定同端口会失败。
   
   建议在所有 early return 前加 `lis.Close()`,或用 defer 模式:
   ```go
   lis, err := net.Listen("tcp", addr)
   if err != nil {
       panic(err)
   }
   success := false
   defer func() {
       if !success {
           lis.Close()
       }
   }()
   // ... TLS setup ...
   // 在 goroutine 启动前:
   success = true
   go func() { server.Serve(lis) }()
   ```



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