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

Goldstein Lyor commented on SSHD-908:
-------------------------------------

The leak seems obvious to me

- the {{SshClient}} is created-started-stopped at a very high rate. While we 
have invested a lot of effort into trying to allow SshClient/Server(s) to be 
re-created/started I strongly advise against it. A Java application should use 
*one* instance (client or server or one of each) and use it to create as many 
sessions as necessary. Therefore the use-case depicted in code seems a bit 
unnatural.

- the {{sshSession}} is not properly disposed of

- ditto for the port forwarding

I understand this might be just some sample code, but if it is supposed to 
detect leaks, at least it should be written in a manner as similar as possible 
as real code - otherwise we will not be able to distinguish real leaks from 
"synthetic" ones due to improper disposal of resources.

Here is how I would expect a program to look like (example is for client but 
similar applies to server):

{code:java|title=Main application code sample}
SshClient client = ...setup and configure...
client.start();

while (...program is active...) {
    try (ClientSession session =  ...connect and auhenticate using the client 
instance) {
     ....
         session.startPortForwarding(....);
        try {
                      ....use the forwarding until no longer necessary...
                      ....see also PortForwardingTracker that can be used as a 
try-with-resource instead of this code block...
        } finally {
           session.stopPortForwarding();
        }
    } 
}

client.stop();
{code}

> Leak of process handles caused by local port forwarding connections
> -------------------------------------------------------------------
>
>                 Key: SSHD-908
>                 URL: https://issues.apache.org/jira/browse/SSHD-908
>             Project: MINA SSHD
>          Issue Type: Bug
>    Affects Versions: 2.1.0
>            Reporter: Roberto Deandrea
>            Priority: Major
>         Attachments: repro.zip
>
>
> Hi,
> We have build an Apache SSHD Client (based on Apache SSHD 2.1.0) to forward 
> local sockets to target servers.
> Our client is configured to use NIO2 builtin service provider, NIO2 Mina 
> service provider and NIO2 Netty service provider.
> We have detected a leak of handles monitoring the java process with ALL above 
> NIO2 service provider.
> When the limit of handles per process is reached, the java process become 
> unresponsive.
>  
> We suspect that the problem could be into Apache SSHD Client code.
> The problem is reproducible in our lab environment.
>  
> Can you help us troubleshoot this problem and in that case what kind of info 
> you need ?
> Did you see a similar problem before and if so, can you give us a solution ?
>  
> Kind Regards
> Roberto Deandrea
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to