mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
fix dial-timeout not affected for client watch command
Signed-off-by: joey <zchengjoey@gmail.com>
This commit is contained in:
parent
c86c93ca29
commit
3d8fe917f9
@ -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"
|
||||
@ -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)
|
||||
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user