Github user lvfangmin commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/592#discussion_r208814126
--- Diff: src/java/main/org/apache/zookeeper/ClientCnxnSocketNIO.java ---
@@ -280,10 +281,14 @@ void registerAndConnect(SocketChannel sock,
InetSocketAddress addr)
@Override
void connect(InetSocketAddress addr) throws IOException {
+ // if UnresolvedAddressException throw on connect and it would
leak a SocketChannelImpl in cancelledKeys EVERY time.
+ // it's hard to deal all situations on socks.cancel,
+ // while an easy way is, ensure DNS resolve successful before
register channel.
+ InetAddress.getByName(addr.getHostName());
--- End diff --
Can you help me understand why sock.close won't clean up the fd?
If we have to check before register, I would suggest to use explicit check
here, like:
if (addr.isUnresolved()) {
throw new UnresolvedAddressException();
}
---