You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ti...@apache.org on 2020/02/20 02:01:49 UTC

[servicecomb-mesher] branch master updated: Dubbo protocol supports timeout configuration (#102)

This is an automated email from the ASF dual-hosted git repository.

tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-mesher.git


The following commit(s) were added to refs/heads/master by this push:
     new 7d3c773  Dubbo protocol supports timeout configuration (#102)
7d3c773 is described below

commit 7d3c773bf74a21c643bbc5e21eb502af90084806
Author: t-xinlin <t_...@sina.com>
AuthorDate: Thu Feb 20 10:01:40 2020 +0800

    Dubbo protocol supports timeout configuration (#102)
    
    * Dubbo protocol supports timeout configuration
    
    * Dubbo protocol supports timeout configuration
    
    * Dubbo protocol supports timeout configuration
---
 .../dubbo/client/chassis/dubbo_chassis_client.go       |  2 +-
 proxy/protocol/dubbo/client/dubbo_client.go            | 18 +++++++++++++-----
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/proxy/protocol/dubbo/client/chassis/dubbo_chassis_client.go b/proxy/protocol/dubbo/client/chassis/dubbo_chassis_client.go
index 2dbdc4a..f878992 100644
--- a/proxy/protocol/dubbo/client/chassis/dubbo_chassis_client.go
+++ b/proxy/protocol/dubbo/client/chassis/dubbo_chassis_client.go
@@ -76,7 +76,7 @@ func (c *dubboChassisClient) Call(ctx context.Context, addr string, inv *invocat
 		return &util.BaseError{"The endpoint is empty"}
 	}
 
-	dubboCli, err := dubboClient.CachedClients.GetClient(endPoint)
+	dubboCli, err := dubboClient.CachedClients.GetClient(endPoint, c.opts.Timeout)
 	if err != nil {
 		resp.Resp.DubboRPCResult.SetException(fmt.Sprintf("Invalid Request addr %s %s", endPoint, err))
 		lager.Logger.Errorf("Invalid Request addr %s %s", endPoint, err)
diff --git a/proxy/protocol/dubbo/client/dubbo_client.go b/proxy/protocol/dubbo/client/dubbo_client.go
index ecf0470..3e72282 100644
--- a/proxy/protocol/dubbo/client/dubbo_client.go
+++ b/proxy/protocol/dubbo/client/dubbo_client.go
@@ -36,6 +36,7 @@ type DubboClient struct {
 	conn          *DubboClientConnection
 	closed        bool
 	routeMgr      *util.RoutineManager
+	Timeout       time.Duration
 }
 
 //WrapResponse is a struct
@@ -70,10 +71,17 @@ func NewClientMgr() *ClientMgr {
 }
 
 //GetClient is a function which returns the particular client for that address
-func (this *ClientMgr) GetClient(addr string) (*DubboClient, error) {
+func (this *ClientMgr) GetClient(addr string, timeout time.Duration) (*DubboClient, error) {
 	this.mapMutex.Lock()
 	defer this.mapMutex.Unlock()
 	if tmp, ok := this.clients[addr]; ok {
+		if timeout <= 0 {
+			timeout = 30 * time.Second
+		}
+		if tmp.Timeout != timeout {
+			tmp.Timeout = timeout
+			this.clients[addr] = tmp
+		}
 		if !tmp.Closed() {
 			lager.Logger.Info("GetClient from cached addr:" + addr)
 			return tmp, nil
@@ -89,7 +97,7 @@ func (this *ClientMgr) GetClient(addr string) (*DubboClient, error) {
 		}
 	}
 	lager.Logger.Info("GetClient from new open addr:" + addr)
-	tmp := NewDubboClient(addr, nil)
+	tmp := NewDubboClient(addr, nil, timeout)
 	err := tmp.Open()
 	if err != nil {
 		return nil, err
@@ -100,10 +108,10 @@ func (this *ClientMgr) GetClient(addr string) (*DubboClient, error) {
 }
 
 //NewDubboClient is a function which creates new dubbo client for given value
-func NewDubboClient(addr string, routeMgr *util.RoutineManager) *DubboClient {
+func NewDubboClient(addr string, routeMgr *util.RoutineManager, timeout time.Duration) *DubboClient {
 	tmp := &DubboClient{}
 	tmp.addr = addr
-
+	tmp.Timeout = timeout
 	tmp.conn = nil
 	tmp.closed = true
 	tmp.msgWaitRspMap = make(map[int64]*RespondResult)
@@ -217,7 +225,7 @@ func (this *DubboClient) Send(dubboReq *dubbo.Request) (*dubbo.DubboRsp, error)
 	select {
 	case <-wait:
 		timeout = false
-	case <-time.After(300 * time.Second):
+	case <-time.After(this.Timeout):
 		timeout = true
 	}
 	if this.closed {