فهرست منبع

Merge pull request #4254 from gyuho/check_wait

client: do not timeout when wait is true
Gyu-Ho Lee 10 سال پیش
والد
کامیت
6413c96024
1فایلهای تغییر یافته به همراه16 افزوده شده و 1 حذف شده
  1. 16 1
      client/client.go

+ 16 - 1
client/client.go

@@ -24,6 +24,7 @@ import (
 	"net/url"
 	"reflect"
 	"sort"
+	"strconv"
 	"sync"
 	"time"
 
@@ -123,6 +124,8 @@ type Config struct {
 	// watch start. But if server is behind some kind of proxy, the response
 	// header may be cached at proxy, and Client cannot rely on this behavior.
 	//
+	// Especially, wait request will ignore this timeout.
+	//
 	// One API call may send multiple requests to different etcd servers until it
 	// succeeds. Use context of the API to specify the overall timeout.
 	//
@@ -442,9 +445,21 @@ func (c *simpleHTTPClient) Do(ctx context.Context, act httpAction) (*http.Respon
 		return nil, nil, err
 	}
 
+	isWait := false
+	if req != nil && req.URL != nil {
+		ws := req.URL.Query().Get("wait")
+		if len(ws) != 0 {
+			var err error
+			isWait, err = strconv.ParseBool(ws)
+			if err != nil {
+				return nil, nil, fmt.Errorf("wrong wait value %s (%v for %+v)", ws, err, req)
+			}
+		}
+	}
+
 	var hctx context.Context
 	var hcancel context.CancelFunc
-	if c.headerTimeout > 0 {
+	if !isWait && c.headerTimeout > 0 {
 		hctx, hcancel = context.WithTimeout(ctx, c.headerTimeout)
 	} else {
 		hctx, hcancel = context.WithCancel(ctx)