[
https://issues.apache.org/jira/browse/ZOOKEEPER-4650?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17646927#comment-17646927
]
Rushabh Shah commented on ZOOKEEPER-4650:
-----------------------------------------
I can think of 2 solutions:
1. Change the order of sock.register and socket.connect in
ClientCnxnSocketNIO#registerAndConnect. If connect fails, then we will not
register socket with selector and hence we will not leak FDs. I don't know if
this is even possible.
{noformat}
void registerAndConnect(SocketChannel sock, InetSocketAddress addr) throws
IOException {
// Create a new ISA instance to avoid reuse of a previously cached
resolution.
boolean immediateConnect =
sock.connect(new InetSocketAddress(addr.getHostString(),
addr.getPort()));
sockKey = sock.register(selector, SelectionKey.OP_CONNECT);
if (immediateConnect) {
sendThread.primeConnection();
}
}
{noformat}
2. Create custom implementation of EpollSelectorImpl and call
EpollSelectorImpl#processDeregisterQueue in close method.
> Zookeeper client leaks file descriptor in case of UnresolvedAddressException
> ----------------------------------------------------------------------------
>
> Key: ZOOKEEPER-4650
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-4650
> Project: ZooKeeper
> Issue Type: Bug
> Components: java client
> Affects Versions: 3.4.14, 3.7.1
> Reporter: Rushabh Shah
> Priority: Major
> Attachments: Screen Shot 2022-12-13 at 4.30.34 PM.png
>
>
> Zookeeper client is causing the file descriptor leak when it is unable to
> properly reach the destination. In this case, the DNS lookup fails but still
> leaves an unbounded TCP socket.
> A colleague took a heap dump of the application. Saw 17400
> sun.nio.ch.SocketChannelImpl object reachable from root and the number
> matched the open file descriptors on the host.
> !Screen Shot 2022-12-13 at 4.30.34 PM.png!
>
> More analysis from the heap dump in the comment.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)