zouyx commented on a change in pull request #471:
URL: https://github.com/apache/dubbo-go/pull/471#discussion_r412009813



##########
File path: config/service_config.go
##########
@@ -160,22 +179,42 @@ func (c *ServiceConfig) Export() error {
                                c.cacheMutex.Unlock()
 
                                invoker := 
extension.GetProxyFactory(providerConfig.ProxyFactory).GetInvoker(*regUrl)
-                               exporter := c.cacheProtocol.Export(invoker)
+                               exporter = c.cacheProtocol.Export(invoker)
                                if exporter == nil {
                                        panic(perrors.New(fmt.Sprintf("Registry 
protocol new exporter error,registry is {%v},url is {%v}", regUrl, ivkURL)))
                                }
                        }
                } else {
                        invoker := 
extension.GetProxyFactory(providerConfig.ProxyFactory).GetInvoker(*ivkURL)
-                       exporter := 
extension.GetProtocol(protocolwrapper.FILTER).Export(invoker)
+                       exporter = 
extension.GetProtocol(protocolwrapper.FILTER).Export(invoker)
                        if exporter == nil {
                                panic(perrors.New(fmt.Sprintf("Filter protocol 
without registry new exporter error,url is {%v}", ivkURL)))
                        }
                }
+               c.exporters = append(c.exporters, exporter)
        }
+       c.exported.Store(true)
        return nil
 }
 
+// Unexport will call unexport of all exporters service config exported
+func (c *ServiceConfig) Unexport() {
+       if !c.exported.Load() {
+               return
+       }
+       if c.unexported.Load() {
+               return
+       }
+       c.exportersLock.Lock()
+       defer c.exportersLock.Unlock()
+       for _, exporter := range c.exporters {
+               exporter.Unexport()
+       }
+       c.exporters = nil

Review comment:
       ```suggestion
        func (){
       c.exportersLock.Lock()
       defer c.exportersLock.Unlock()
               for _, exporter := range c.exporters {
           exporter.Unexport()
       }
       c.exporters = nil
       }()
   ```




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to