[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-4525?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17525417#comment-17525417
 ] 

houshuai commented on ZOOKEEPER-4525:
-------------------------------------

I have a fix for this issue on [https://github.com/apache/zookeeper/pull/1864]

[~kezhuw] please take a look.

> Thread leaks occur when resolve address failed.
> -----------------------------------------------
>
>                 Key: ZOOKEEPER-4525
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-4525
>             Project: ZooKeeper
>          Issue Type: Bug
>          Components: java client
>    Affects Versions: 3.6.3
>         Environment: {code:java}
> import org.apache.zookeeper.ClientCnxn;
> import org.apache.zookeeper.ZooKeeper;
> import org.apache.zookeeper.server.ZooKeeperThread;
> import java.lang.reflect.Field;
> public class Main extends Thread {
>     public static void main(String[] args) {
>         new Main().start();
>     }
>     @Override
>     public void run() {
>         System.setProperty("zookeeper.serverCnxnFactory", 
> "org.apache.zookeeper.server.NettyServerCnxnFactory");
>         System.setProperty("zookeeper.clientCnxnSocket", 
> "org.apache.zookeeper.ClientCnxnSocketNetty");
>         ZooKeeperThread eventThread = null;
>         try {
>             ZooKeeper zooKeeper = new ZooKeeper("a.local:4096", 50000, 
> watchedEvent -> {
>             });
>             Field cnxnField = zooKeeper.getClass().getDeclaredField("cnxn");
>             cnxnField.setAccessible(true);
>             ClientCnxn clientCnxn = (ClientCnxn) cnxnField.get(zooKeeper);
>             Field eventThreadField = 
> clientCnxn.getClass().getDeclaredField("eventThread");
>             eventThreadField.setAccessible(true);
>             eventThread = (ZooKeeperThread) eventThreadField.get(clientCnxn);
>             zooKeeper.close();
>         } catch (Exception ignore) {
>             ignore.printStackTrace();
>         }
>         System.out.println(eventThread.getState());
>     }
> }
>  {code}
>            Reporter: houshuai
>            Priority: Major
>         Attachments: stacktrace.txt
>
>
> In version 3.6. When connecting zookeeper using domain name with Netty. If 
> the domain name failed to resolve, calling Zookeeper::close cannot close the 
> EventThread. It will cause thread leaks.
>  
> When resolve address failed, the connect thread in ClientCnxn throws an 
> UnknownHostException. ClientCnxnSocketNetty.firstConnect has not been 
> initialized.
>  
> When the close method is called, it calls firstConnect.countDown().It will 
> throw a NullPointerException and the thread cannot be closed properly.
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to