This is an automated email from the ASF dual-hosted git repository.
littlecui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-kie.git
The following commit(s) were added to refs/heads/master by this push:
new 24016a7 when etcd connection fails, if wait is not empty, set the
timeout to wait (#223)
24016a7 is described below
commit 24016a77b890e15504c427e3528ba44843619e23
Author: Sphairis <[email protected]>
AuthorDate: Wed Oct 20 15:28:55 2021 +0800
when etcd connection fails, if wait is not empty, set the timeout to wait
(#223)
* when etcd connection fails, if wait is not empty, set the timeout to wait
* when etcd connection fails, if wait is not empty, set the timeout to wait
* fix error
Co-authored-by: SphaIris <aaalixiaopei123>
---
server/resource/v1/kv_resource.go | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/server/resource/v1/kv_resource.go
b/server/resource/v1/kv_resource.go
index 5caacd7..b568aab 100644
--- a/server/resource/v1/kv_resource.go
+++ b/server/resource/v1/kv_resource.go
@@ -19,9 +19,11 @@
package v1
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
+ "time"
"github.com/apache/servicecomb-kie/server/datasource"
kvsvc "github.com/apache/servicecomb-kie/server/service/kv"
@@ -200,6 +202,17 @@ func (r *KVResource) List(rctx *restful.Context) {
func returnData(rctx *restful.Context, request *model.ListKVRequest) {
revStr := rctx.ReadQueryParameter(common.QueryParamRev)
wait := rctx.ReadQueryParameter(common.QueryParamWait)
+ if wait != "" {
+ duration, err := time.ParseDuration(wait)
+ if err != nil {
+ WriteErrResponse(rctx, config.ErrInvalidParams,
err.Error())
+ return
+ }
+
+ var cancel context.CancelFunc
+ rctx.Ctx, cancel = context.WithTimeout(rctx.Ctx, duration)
+ defer cancel()
+ }
if revStr == "" {
if wait == "" {
queryAndResponse(rctx, request)