You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/02/07 15:51:52 UTC

[GitHub] [dubbo-go] flycash commented on a change in pull request #1045: Imp: destroy invoker smoothly

flycash commented on a change in pull request #1045:
URL: https://github.com/apache/dubbo-go/pull/1045#discussion_r571636678



##########
File path: protocol/dubbo/dubbo_invoker.go
##########
@@ -87,15 +93,24 @@ func (di *DubboInvoker) Invoke(ctx context.Context, invocation protocol.Invocati
 		err    error
 		result protocol.RPCResult
 	)
-	if atomic.LoadInt64(&di.reqNum) < 0 {
+	if !di.BaseInvoker.IsAvailable() {

Review comment:
       It's double-check pattern, I think.

##########
File path: protocol/grpc/grpc_invoker.go
##########
@@ -83,21 +127,47 @@ func (gi *GrpcInvoker) Invoke(ctx context.Context, invocation protocol.Invocatio
 
 // IsAvailable get available status
 func (gi *GrpcInvoker) IsAvailable() bool {
-	return gi.BaseInvoker.IsAvailable() && gi.client.GetState() != connectivity.Shutdown
+	client := gi.getClient()
+	if client != nil {
+		return gi.BaseInvoker.IsAvailable() && client.GetState() != connectivity.Shutdown
+	}
+
+	return false
 }
 
 // IsDestroyed get destroyed status
 func (gi *GrpcInvoker) IsDestroyed() bool {
-	return gi.BaseInvoker.IsDestroyed() && gi.client.GetState() == connectivity.Shutdown
+	client := gi.getClient()
+	if client != nil {
+		return gi.BaseInvoker.IsDestroyed() && client.GetState() == connectivity.Shutdown
+	}
+
+	return false
 }
 
 // Destroy will destroy gRPC's invoker and client, so it is only called once
 func (gi *GrpcInvoker) Destroy() {
 	gi.quitOnce.Do(func() {
-		gi.BaseInvoker.Destroy()
-
-		if gi.client != nil {
-			_ = gi.client.Close()
+		gi.BaseInvoker.Stop()
+		var times int64
+		for {
+			times = gi.BaseInvoker.InvokeTimes()
+			if times == 0 {
+				gi.BaseInvoker.AddInvokerTimes(-1)
+				logger.Infof("grpcInvoker is destroyed, url:{%s}", gi.GetUrl().Key())
+				gi.BaseInvoker.Destroy()
+				client := gi.getClient()
+				if client != nil {
+					client.Close()
+					gi.setClient(nil)

Review comment:
       I am not sure whether exchange those two lines' order:
   ```
   gi.setClient(nil)
   client.Close()
   ```
   It looks more safe.

##########
File path: protocol/dubbo/dubbo_invoker.go
##########
@@ -162,27 +181,38 @@ func (di *DubboInvoker) getTimeout(invocation *invocation_impl.RPCInvocation) ti
 }
 
 func (di *DubboInvoker) IsAvailable() bool {
-	return di.client.IsAvailable()
+	client := di.getClient()
+	if client != nil {
+		return client.IsAvailable()
+	}
+
+	return false
 }
 
 // Destroy destroy dubbo client invoker.
 func (di *DubboInvoker) Destroy() {
 	di.quitOnce.Do(func() {
+		di.BaseInvoker.Stop()
+		var times int64
 		for {
-			if di.reqNum == 0 {
-				di.reqNum = -1
-				logger.Infof("dubboInvoker is destroyed,url:{%s}", di.GetUrl().Key())
+			times = di.BaseInvoker.InvokeTimes()
+			if times == 0 {
+				di.BaseInvoker.AddInvokerTimes(-1)

Review comment:
       -1 indicates `BaseInvoker` is unavailable




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org