Skip to content

Commit a826289

Browse files
Fix/remove setdeadline (#2785)
1 parent 761f0e0 commit a826289

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

protocol/rest/client/client_impl/resty_client.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"net"
2323
"net/http"
2424
"path"
25-
"time"
2625
)
2726

2827
import (
@@ -56,13 +55,11 @@ func NewRestyClient(restOption *client.RestOptions) client.RestClient {
5655
if err != nil {
5756
return nil, err
5857
}
59-
err = c.SetDeadline(time.Now().Add(restOption.RequestTimeout))
60-
if err != nil {
61-
return nil, err
62-
}
6358
return c, nil
6459
},
60+
IdleConnTimeout: restOption.KeppAliveTimeout,
6561
})
62+
client.SetTimeout(restOption.RequestTimeout)
6663
return &RestyClient{
6764
client: client,
6865
}

protocol/rest/client/rest_client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import (
2323
)
2424

2525
type RestOptions struct {
26-
RequestTimeout time.Duration
27-
ConnectTimeout time.Duration
26+
RequestTimeout time.Duration
27+
ConnectTimeout time.Duration
28+
KeppAliveTimeout time.Duration
2829
}
2930

3031
type RestClientRequest struct {

protocol/rest/rest_protocol.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func (rp *RestProtocol) Refer(url *common.URL) protocol.Invoker {
9393
requestTimeout := time.Duration(3 * time.Second)
9494
requestTimeoutStr := url.GetParam(constant.TimeoutKey, "3s")
9595
connectTimeout := requestTimeout // config.GetConsumerConfig().ConnectTimeout
96+
keepAliveTimeout := url.GetParamDuration(constant.KeepAliveTimeout, constant.DefaultKeepAliveTimeout)
9697
// end
9798
if t, err := time.ParseDuration(requestTimeoutStr); err == nil {
9899
requestTimeout = t
@@ -103,7 +104,7 @@ func (rp *RestProtocol) Refer(url *common.URL) protocol.Invoker {
103104
logger.Errorf("%s service doesn't has consumer config", url.Path)
104105
return nil
105106
}
106-
restOptions := client.RestOptions{RequestTimeout: requestTimeout, ConnectTimeout: connectTimeout}
107+
restOptions := client.RestOptions{RequestTimeout: requestTimeout, ConnectTimeout: connectTimeout, KeppAliveTimeout: keepAliveTimeout}
107108
restClient := rp.getClient(restOptions, restServiceConfig.Client)
108109
invoker := NewRestInvoker(url, &restClient, restServiceConfig.RestMethodConfigsMap)
109110
rp.SetInvokers(invoker)

0 commit comments

Comments
 (0)