@@ -26,6 +26,7 @@ import (
26
26
"github.com/spf13/cobra"
27
27
"github.com/spf13/pflag"
28
28
"go.uber.org/zap"
29
+ "google.golang.org/grpc"
29
30
"google.golang.org/grpc/grpclog"
30
31
31
32
"go.etcd.io/etcd/client/pkg/v3/logutil"
@@ -151,6 +152,11 @@ func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
151
152
return mustClient (cfg )
152
153
}
153
154
155
+ func mustBlockClientFromCmd (cmd * cobra.Command ) * clientv3.Client {
156
+ cfg := clientConfigFromCmd (cmd )
157
+ return mustBlockClient (cfg )
158
+ }
159
+
154
160
func mustClient (cc * clientv3.ConfigSpec ) * clientv3.Client {
155
161
lg , _ := logutil .CreateDefaultZapLogger (zap .InfoLevel )
156
162
cfg , err := clientv3 .NewClientConfig (cc , lg )
@@ -166,6 +172,23 @@ func mustClient(cc *clientv3.ConfigSpec) *clientv3.Client {
166
172
return client
167
173
}
168
174
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
+
169
192
func argOrStdin (args []string , stdin io.Reader , i int ) (string , error ) {
170
193
if i < len (args ) {
171
194
return args [i ], nil
0 commit comments