Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Duplicate
-
3.6.3
-
None
-
None
-
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()); } }
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()); } }
Description
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.
Attachments
Attachments
Issue Links
- duplicates
-
ZOOKEEPER-4296 NullPointerException when ClientCnxnSocketNetty is closed without being opened
- Closed