You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@zookeeper.apache.org by "houshuai (Jira)" <ji...@apache.org> on 2022/04/21 04:20:00 UTC

[jira] [Created] (ZOOKEEPER-4525) Thread leaks occur when resolve address failed.

houshuai created ZOOKEEPER-4525:
-----------------------------------

             Summary: 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
         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)