You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by zh...@apache.org on 2025/03/03 02:31:53 UTC

(dubbo-go) branch develop updated: Fix/remove setdeadline (#2785)

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

zhangwenfeng pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/develop by this push:
     new a82628947 Fix/remove setdeadline (#2785)
a82628947 is described below

commit a8262894711c433dcfbd6b9484f0cf3875f31579
Author: xinfan.wu <no...@gmail.com>
AuthorDate: Mon Mar 3 10:31:48 2025 +0800

    Fix/remove setdeadline (#2785)
---
 protocol/rest/client/client_impl/resty_client.go | 7 ++-----
 protocol/rest/client/rest_client.go              | 5 +++--
 protocol/rest/rest_protocol.go                   | 3 ++-
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/protocol/rest/client/client_impl/resty_client.go b/protocol/rest/client/client_impl/resty_client.go
index 7044a53d2..26989d2b3 100644
--- a/protocol/rest/client/client_impl/resty_client.go
+++ b/protocol/rest/client/client_impl/resty_client.go
@@ -22,7 +22,6 @@ import (
 	"net"
 	"net/http"
 	"path"
-	"time"
 )
 
 import (
@@ -56,13 +55,11 @@ func NewRestyClient(restOption *client.RestOptions) client.RestClient {
 				if err != nil {
 					return nil, err
 				}
-				err = c.SetDeadline(time.Now().Add(restOption.RequestTimeout))
-				if err != nil {
-					return nil, err
-				}
 				return c, nil
 			},
+			IdleConnTimeout: restOption.KeppAliveTimeout,
 		})
+	client.SetTimeout(restOption.RequestTimeout)
 	return &RestyClient{
 		client: client,
 	}
diff --git a/protocol/rest/client/rest_client.go b/protocol/rest/client/rest_client.go
index 2215da4c2..daa491a98 100644
--- a/protocol/rest/client/rest_client.go
+++ b/protocol/rest/client/rest_client.go
@@ -23,8 +23,9 @@ import (
 )
 
 type RestOptions struct {
-	RequestTimeout time.Duration
-	ConnectTimeout time.Duration
+	RequestTimeout   time.Duration
+	ConnectTimeout   time.Duration
+	KeppAliveTimeout time.Duration
 }
 
 type RestClientRequest struct {
diff --git a/protocol/rest/rest_protocol.go b/protocol/rest/rest_protocol.go
index 303b45353..59a4741b2 100644
--- a/protocol/rest/rest_protocol.go
+++ b/protocol/rest/rest_protocol.go
@@ -93,6 +93,7 @@ func (rp *RestProtocol) Refer(url *common.URL) protocol.Invoker {
 	requestTimeout := time.Duration(3 * time.Second)
 	requestTimeoutStr := url.GetParam(constant.TimeoutKey, "3s")
 	connectTimeout := requestTimeout // config.GetConsumerConfig().ConnectTimeout
+	keepAliveTimeout := url.GetParamDuration(constant.KeepAliveTimeout, constant.DefaultKeepAliveTimeout)
 	// end
 	if t, err := time.ParseDuration(requestTimeoutStr); err == nil {
 		requestTimeout = t
@@ -103,7 +104,7 @@ func (rp *RestProtocol) Refer(url *common.URL) protocol.Invoker {
 		logger.Errorf("%s service doesn't has consumer config", url.Path)
 		return nil
 	}
-	restOptions := client.RestOptions{RequestTimeout: requestTimeout, ConnectTimeout: connectTimeout}
+	restOptions := client.RestOptions{RequestTimeout: requestTimeout, ConnectTimeout: connectTimeout, KeppAliveTimeout: keepAliveTimeout}
 	restClient := rp.getClient(restOptions, restServiceConfig.Client)
 	invoker := NewRestInvoker(url, &restClient, restServiceConfig.RestMethodConfigsMap)
 	rp.SetInvokers(invoker)