Snow-kal commented on code in PR #3198:
URL: https://github.com/apache/dubbo-go/pull/3198#discussion_r2779147917


##########
remoting/getty/getty_client_test.go:
##########
@@ -83,10 +82,7 @@ func setAttachment(invocation *invocation.RPCInvocation, 
attachments map[string]
 }
 
 func getClient(url *common.URL) *Client {
-       client := NewClient(Options{
-               // todo fix timeout
-               ConnectTimeout: 3 * time.Second, // 
config.GetConsumerConfig().ConnectTimeout,
-       })

Review Comment:
   解决方案是这样
   在创建 client 连接时不断等待会话建立,如果超过指定时长就主动关闭 client 并返回错误,从而避免无限等待。
   
   ```
   func getClient(url *common.URL) *Client {
       defaultTimeout := url.GetParam(constant.TimeoutKey, "3s")
       client := NewClient(Options{
           ConnectTimeout: url.GetParamDuration("connect.timeout", 
defaultTimeout),
       })
       if err := client.Connect(url); err != nil {
           return nil
       }
       return client
   }
   ```
   
   getty_client_test  文件
   解释: 从 URL 里取 connect.timeout,没有则用 timeout 或默认值
   ```
   
   func NewClient(opt Options) *Client {
       switch {
       case opt.ConnectTimeout == 0:
           opt.ConnectTimeout = 3 * time.Second
           fallthrough
       case opt.RequestTimeout == 0:
           opt.RequestTimeout = 3 * time.Second
       }
   
       c := &Client{
           opts:         opt,
           clientClosed: false,
       }
       c.gettyClientCreated.Store(false)
       return c
   }
   ```
   getty_client 文件
   解释:如果未配置,则默认设置 ConnectTimeout = 3s 



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