浏览代码

etcdctl/ctlv2: total-timeout for Sync

Fix https://github.com/coreos/etcd/issues/4897.
Gyu-Ho Lee 9 年之前
父节点
当前提交
62a9209088
共有 1 个文件被更改,包括 8 次插入2 次删除
  1. 8 2
      etcdctl/ctlv2/command/util.go

+ 8 - 2
etcdctl/ctlv2/command/util.go

@@ -156,7 +156,13 @@ func getTransport(c *cli.Context) (*http.Transport, error) {
 		CertFile: certfile,
 		KeyFile:  keyfile,
 	}
-	return transport.NewTransport(tls, defaultDialTimeout)
+
+	dialTimeout := defaultDialTimeout
+	totalTimeout := c.GlobalDuration("total-timeout")
+	if totalTimeout != 0 && totalTimeout < dialTimeout {
+		dialTimeout = totalTimeout
+	}
+	return transport.NewTransport(tls, dialTimeout)
 }
 
 func getUsernamePasswordFromFlag(usernameFlag string) (username string, password string, err error) {
@@ -203,7 +209,7 @@ func mustNewClient(c *cli.Context) client.Client {
 		if debug {
 			fmt.Fprintf(os.Stderr, "start to sync cluster using endpoints(%s)\n", strings.Join(hc.Endpoints(), ","))
 		}
-		ctx, cancel := context.WithTimeout(context.Background(), client.DefaultRequestTimeout)
+		ctx, cancel := contextWithTotalTimeout(c)
 		err := hc.Sync(ctx)
 		cancel()
 		if err != nil {