From a236ce4519d2e0058723fdf2c4f4859090afe402 Mon Sep 17 00:00:00 2001 From: Congqi Xia Date: Fri, 26 Apr 2024 18:30:20 +0800 Subject: [PATCH] fix: Make custom DialOption overwrite default ones See also #699 Signed-off-by: Congqi Xia --- client/config.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/client/config.go b/client/config.go index 5293f537a..49c178063 100644 --- a/client/config.go +++ b/client/config.go @@ -136,13 +136,7 @@ func (c *Config) setIdentifier(identifier string) { // Get parsed grpc dial options, should be called after parse was called. func (c *Config) getDialOption() []grpc.DialOption { - options := c.DialOptions - if c.DialOptions == nil { - // Add default connection options. - options = make([]grpc.DialOption, len(DefaultGrpcOpts)) - copy(options, DefaultGrpcOpts) - } - + var options []grpc.DialOption // Construct dial option. if c.EnableTLSAuth { options = append(options, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) @@ -150,6 +144,13 @@ func (c *Config) getDialOption() []grpc.DialOption { options = append(options, grpc.WithTransportCredentials(insecure.NewCredentials())) } + if c.DialOptions == nil { + // Add default connection options. + options = append(options, DefaultGrpcOpts...) + } else { + options = append(options, c.DialOptions...) + } + options = append(options, grpc.WithChainUnaryInterceptor(grpc_retry.UnaryClientInterceptor( grpc_retry.WithMax(6),