Skip to content

Commit 3d8fe91

Browse files
committed
fix dial-timeout not affected for client watch command
Signed-off-by: joey <[email protected]>
1 parent c86c93c commit 3d8fe91

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

etcdctl/ctlv3/command/global.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/spf13/cobra"
2727
"github.com/spf13/pflag"
2828
"go.uber.org/zap"
29+
"google.golang.org/grpc"
2930
"google.golang.org/grpc/grpclog"
3031

3132
"go.etcd.io/etcd/client/pkg/v3/logutil"
@@ -151,6 +152,11 @@ func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
151152
return mustClient(cfg)
152153
}
153154

155+
func mustBlockClientFromCmd(cmd *cobra.Command) *clientv3.Client {
156+
cfg := clientConfigFromCmd(cmd)
157+
return mustBlockClient(cfg)
158+
}
159+
154160
func mustClient(cc *clientv3.ConfigSpec) *clientv3.Client {
155161
lg, _ := logutil.CreateDefaultZapLogger(zap.InfoLevel)
156162
cfg, err := clientv3.NewClientConfig(cc, lg)
@@ -166,6 +172,23 @@ func mustClient(cc *clientv3.ConfigSpec) *clientv3.Client {
166172
return client
167173
}
168174

175+
// mustBlockClient same as mustClient but with grpc.WithBlock dial option, detail see #18335
176+
func mustBlockClient(cc *clientv3.ConfigSpec) *clientv3.Client {
177+
lg, _ := logutil.CreateDefaultZapLogger(zap.InfoLevel)
178+
cfg, err := clientv3.NewClientConfig(cc, lg)
179+
if err != nil {
180+
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)
181+
}
182+
183+
cfg.DialOptions = append(cfg.DialOptions, grpc.WithBlock())
184+
client, err := clientv3.New(*cfg)
185+
if err != nil {
186+
cobrautl.ExitWithError(cobrautl.ExitBadConnection, err)
187+
}
188+
189+
return client
190+
}
191+
169192
func argOrStdin(args []string, stdin io.Reader, i int) (string, error) {
170193
if i < len(args) {
171194
return args[i], nil

etcdctl/ctlv3/command/watch_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func watchCommandFunc(cmd *cobra.Command, args []string) {
7878
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)
7979
}
8080

81-
c := mustClientFromCmd(cmd)
81+
c := mustBlockClientFromCmd(cmd)
8282
wc, err := getWatchChan(c, watchArgs)
8383
if err != nil {
8484
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)

0 commit comments

Comments
 (0)