Skip to content

Commit 203dba3

Browse files
authored
Merge pull request #38 from KyberNetwork/fix/grpc-client-onupdate
fix: new grpc client is accidentally closed when updating new config
2 parents 1b30443 + 4a035c5 commit 203dba3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

pkg/client/grpc.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,7 @@ func (c *GrpcCfg[T]) WithFactory(clientFactory func(grpc.ClientConnInterface) T)
3131

3232
func (*GrpcCfg[T]) OnUpdate(old, new *GrpcCfg[T]) {
3333
ctx := context.Background()
34-
var err error
35-
new.grpcClient, err = grpcclient.New(new.clientFactory, grpcclient.WithConfig(&new.Config))
36-
if err != nil {
37-
klog.Errorf(ctx, "GrpcCfg.OnUpdate|grpcclient.New failed|err=%v", err)
38-
return
39-
}
4034

41-
new.C = new.grpcClient.C
4235
if old != nil {
4336
oldGrpcClient := old.grpcClient
4437
time.AfterFunc(GrpcCloseDelay, func() {
@@ -47,4 +40,13 @@ func (*GrpcCfg[T]) OnUpdate(old, new *GrpcCfg[T]) {
4740
}
4841
})
4942
}
43+
44+
var err error
45+
new.grpcClient, err = grpcclient.New(new.clientFactory, grpcclient.WithConfig(&new.Config))
46+
if err != nil {
47+
klog.Errorf(ctx, "GrpcCfg.OnUpdate|grpcclient.New failed|err=%v", err)
48+
return
49+
}
50+
51+
new.C = new.grpcClient.C
5052
}

0 commit comments

Comments
 (0)