Skip to content

Commit

Permalink
fix dial-timeout not affected for client watch command
Browse files Browse the repository at this point in the history
Signed-off-by: joey <[email protected]>
  • Loading branch information
chengjoey committed Jul 20, 2024
1 parent bc9801f commit 8caf4d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions etcdctl/ctlv3/command/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/grpclog"

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

func mustBlockClientFromCmd(cmd *cobra.Command) *clientv3.Client {
cfg := clientConfigFromCmd(cmd)
return mustBlockClient(cfg)
}

func mustClient(cc *clientv3.ConfigSpec) *clientv3.Client {
lg, _ := logutil.CreateDefaultZapLogger(zap.InfoLevel)
cfg, err := clientv3.NewClientConfig(cc, lg)
Expand All @@ -166,6 +172,23 @@ func mustClient(cc *clientv3.ConfigSpec) *clientv3.Client {
return client
}

// mustBlockClient same as mustClient but with grpc.WithBlock dial option, detail see #18335
func mustBlockClient(cc *clientv3.ConfigSpec) *clientv3.Client {
lg, _ := logutil.CreateDefaultZapLogger(zap.InfoLevel)
cfg, err := clientv3.NewClientConfig(cc, lg)
if err != nil {
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)
}

cfg.DialOptions = append(cfg.DialOptions, grpc.WithBlock())
client, err := clientv3.New(*cfg)
if err != nil {
cobrautl.ExitWithError(cobrautl.ExitBadConnection, err)
}

return client
}

func argOrStdin(args []string, stdin io.Reader, i int) (string, error) {
if i < len(args) {
return args[i], nil
Expand Down
2 changes: 1 addition & 1 deletion etcdctl/ctlv3/command/watch_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func watchCommandFunc(cmd *cobra.Command, args []string) {
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)
}

c := mustClientFromCmd(cmd)
c := mustBlockClientFromCmd(cmd)
wc, err := getWatchChan(c, watchArgs)
if err != nil {
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)
Expand Down

0 comments on commit 8caf4d0

Please sign in to comment.