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/09/23 15:54:44 UTC

[GitHub] [dubbo] zrlw commented on issue #8880: LazyConnectExchangeClient关闭后没有将client重置为null

zrlw commented on issue #8880:
URL: https://github.com/apache/dubbo/issues/8880#issuecomment-925942857


   顺便修订了 #7410 引入的缺陷,该缺陷将会导致热加载的dubbo Reference关闭时不释放连接,问题详情见 #8872
   
   重现方法:
   1. install当前master分支(2.7.14-SNAPSHOT)dubbo
   2.  修改dubbo-samples的dubbo-samples-basic工程pom文件的dubbo版本为2.7.14-SNAPSHOT
   3. 在工程中增加热加载Reference类CommuLink
   ```
   package org.apache.dubbo.samples.basic;
   
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
   
   import org.apache.dubbo.config.ApplicationConfig;
   import org.apache.dubbo.config.ReferenceConfig;
   import org.apache.dubbo.config.RegistryConfig;
   import org.apache.dubbo.rpc.Invoker;
   import org.apache.dubbo.samples.basic.api.DemoService;
   
   public class CommuLink {
       private ReferenceConfig<DemoService> reference = null;
       private DemoService uChannelInstance = null;
       
       public DemoService getuChannelInstance() {
           return uChannelInstance;
       }
   
       public boolean init(ApplicationConfig applicationConfig) {
           //需要初始化
           this.reference = new ReferenceConfig<>();
           reference.setApplication(applicationConfig);
           reference.setInterface(DemoService.class);
           //reference.setCheck(false);
           //reference.setConnections(5);
           
           try{
               this.uChannelInstance = reference.get();
               return true;
           }catch(Exception e){
           }
           return false;
       }
       
       public void close() {
           try {
               Method getInvoker = ReferenceConfig.class.getDeclaredMethod("getInvoker");
               getInvoker.setAccessible(true);
               Invoker<?> invoker = (Invoker<?>) getInvoker.invoke(reference);
               invoker.destroyAll();
               reference.destroy();
           } catch (NoSuchMethodException e) {
               e.printStackTrace();
           } catch (IllegalAccessException e) {
               e.printStackTrace();
           } catch (InvocationTargetException e) {
               e.printStackTrace();
           }
       }
   
       public static void main(String[] args) {
           RegistryConfig registryConfig = new RegistryConfig();
           registryConfig.setAddress("zookeeper://127.0.0.1:2181");
           
           ApplicationConfig applicationConfig = new ApplicationConfig("commuLink");
           applicationConfig.setQosEnable(false);
           applicationConfig.setRegistry(registryConfig);
           
           CommuLink lastLink = null;
           for(int i = 0;i < 10;i++){
               if(lastLink != null){
                   lastLink.close();
               }
               CommuLink commuLink = new CommuLink();
               commuLink.init(applicationConfig);
               String hello = commuLink.getuChannelInstance().sayHello("name-" + i);
               System.out.println(hello);
               lastLink = commuLink;
   
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
               }
               System.out.println(i);
           }
       }
   }
   ```
   4. 启动BasicProvider(内置zk)
   5. 在HeaderExchangeChannel的两个close方法设置断点,然后debug跟踪CommuLink,用netstat -an看20880连接是否断开。


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

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