You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2022/10/27 02:53:30 UTC

[incubator-eventmesh] branch master updated: rollback logic

This is an automated email from the ASF dual-hosted git repository.

mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new 07a79380 rollback logic
     new f14f7818 Merge pull request #1940 from walterlife/rollback-golangsdk-logic
07a79380 is described below

commit 07a79380e5d912bd9536978795817cdb5d5c3e99
Author: yuweizhu <yu...@tencent.com>
AuthorDate: Wed Oct 26 23:28:52 2022 +0800

    rollback logic
---
 eventmesh-sdk-go/grpc/client.go | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/eventmesh-sdk-go/grpc/client.go b/eventmesh-sdk-go/grpc/client.go
index 30ddf5e1..96abf56a 100644
--- a/eventmesh-sdk-go/grpc/client.go
+++ b/eventmesh-sdk-go/grpc/client.go
@@ -59,10 +59,20 @@ func newEventMeshGRPCClient(cfg *conf.GRPCConfig, opts ...GRPCOption) (*eventMes
 	var (
 		err         error
 		ctx, cancel = context.WithCancel(context.Background())
+		grpConn     *grpc.ClientConn
 	)
 	if err = conf.ValidateDefaultConf(cfg); err != nil {
 		return nil, err
 	}
+	defer func() {
+		if err != nil && grpConn != nil {
+			// if err != nil and the grpc.ClientConn is connected
+			// we need to close it
+			if err := grpConn.Close(); err != nil {
+				log.Warnf("failed to close conn with, err:%v", err)
+			}
+		}
+	}()
 	makeGRPCConn := func(host string, port int) (*grpc.ClientConn, error) {
 		addr := fmt.Sprintf("%v:%v", host, port)
 		conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
@@ -84,10 +94,11 @@ func newEventMeshGRPCClient(cfg *conf.GRPCConfig, opts ...GRPCOption) (*eventMes
 		cli.seqg = seq.NewAtomicSeq()
 	}
 	time.Sleep(time.Nanosecond * time.Duration(rand.Int31n(50)))
-	grpConn, err := makeGRPCConn(cfg.Host, cfg.Port)
+	conn, err := makeGRPCConn(cfg.Host, cfg.Port)
 	if err != nil {
 		return nil, err
 	}
+	grpConn = conn
 	producer, err := newProducer(grpConn)
 	if err != nil {
 		log.Warnf("failed to create producer, err:%v", err)
@@ -179,10 +190,8 @@ func (e *eventMeshGRPCClient) Close() error {
 		}
 		e.eventMeshConsumer = nil
 	}
-	if e.grpcConn != nil {
-		if err := e.grpcConn.Close(); err != nil {
-			log.Warnf("err in close conn with err:%v", err)
-		}
+	if err := e.grpcConn.Close(); err != nil {
+		log.Warnf("err in close conn with err:%v", err)
 	}
 
 	log.Infof("success close grpc client")


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org