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

Zhenliang Su commented on SSHD-921:
-----------------------------------

It does fixed this problem, but the nio thread will never be released.

{code:java}
"sshd-SshClient[3d11a4e7]-nio2-thread-3" #29 daemon prio=5 os_prio=0 
tid=0x00000000208c5000 nid=0x659c in Object.wait() [0x0000000022a5d000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x000000076f436c98> (a 
java.util.concurrent.ArrayBlockingQueue)
        at java.lang.Object.wait(Unknown Source)
        at 
org.apache.sshd.agent.local.AgentForwardedChannel.request(AgentForwardedChannel.java:84)
        - locked <0x000000076f436c98> (a 
java.util.concurrent.ArrayBlockingQueue)
        at 
org.apache.sshd.agent.local.AgentForwardedChannel$1.request(AgentForwardedChannel.java:59)
        at 
org.apache.sshd.agent.common.AbstractAgentProxy.getIdentities(AbstractAgentProxy.java:79)
        at 
org.apache.sshd.client.auth.pubkey.UserAuthPublicKeyIterator$2.<init>(UserAuthPublicKeyIterator.java:154)
        at 
org.apache.sshd.client.auth.pubkey.UserAuthPublicKeyIterator.initializeAgentIdentities(UserAuthPublicKeyIterator.java:152)
        at 
org.apache.sshd.client.auth.pubkey.UserAuthPublicKeyIterator.<init>(UserAuthPublicKeyIterator.java:59)
        at 
org.apache.sshd.client.auth.pubkey.UserAuthPublicKey.init(UserAuthPublicKey.java:77)
        at 
org.apache.sshd.client.session.ClientUserAuthService.tryNext(ClientUserAuthService.java:345)
        at 
org.apache.sshd.client.session.ClientUserAuthService.processUserAuth(ClientUserAuthService.java:267)
        at 
org.apache.sshd.client.session.ClientUserAuthService.process(ClientUserAuthService.java:214)
        at 
org.apache.sshd.common.session.helpers.AbstractSession.doHandleMessage(AbstractSession.java:435)
        at 
org.apache.sshd.common.session.helpers.AbstractSession.handleMessage(AbstractSession.java:362)
        - locked <0x000000076f4ed700> (a java.lang.Object)
        at 
org.apache.sshd.common.session.helpers.AbstractSession.decode(AbstractSession.java:1207)
        at 
org.apache.sshd.common.session.helpers.AbstractSession.messageReceived(AbstractSession.java:323)
        - locked <0x000000076f53b278> (a java.lang.Object)
        at 
org.apache.sshd.common.session.helpers.AbstractSessionIoHandler.messageReceived(AbstractSessionIoHandler.java:63)
        at 
org.apache.sshd.common.io.nio2.Nio2Session.handleReadCycleCompletion(Nio2Session.java:368)
        at 
org.apache.sshd.common.io.nio2.Nio2Session$1.onCompleted(Nio2Session.java:346)
        at 
org.apache.sshd.common.io.nio2.Nio2Session$1.onCompleted(Nio2Session.java:1)
        at 
org.apache.sshd.common.io.nio2.Nio2CompletionHandler.lambda$0(Nio2CompletionHandler.java:38)
        at 
org.apache.sshd.common.io.nio2.Nio2CompletionHandler$$Lambda$37/606422495.run(Unknown
 Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at 
org.apache.sshd.common.io.nio2.Nio2CompletionHandler.completed(Nio2CompletionHandler.java:37)
        at sun.nio.ch.Invoker.invokeUnchecked(Unknown Source)
        at sun.nio.ch.Invoker$2.run(Unknown Source)
        at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

   Locked ownable synchronizers:
        - <0x000000076f4e7160> (a 
java.util.concurrent.ThreadPoolExecutor$Worker)

{code}


> OutOfMemory Error in extreme situations
> ---------------------------------------
>
>                 Key: SSHD-921
>                 URL: https://issues.apache.org/jira/browse/SSHD-921
>             Project: MINA SSHD
>          Issue Type: Bug
>    Affects Versions: 1.7.0, 2.0.0
>            Reporter: Zhenliang Su
>            Assignee: Goldstein Lyor
>            Priority: Major
>         Attachments: Main.java, jstack.txt
>
>
> The demo code run in my local machine.
>  When I 'ssh [email protected] -p 2233', my demo will use the agent forwarding 
> feature to login 10.10.16.201.
>  In most cases, it's ok. But in few cases, for example, client disconnect 
> suddenly, it will lead to OutOfMemory Error.
>  To simulate this scenario of OutOfMemory Error, I did some trick to the sshd 
> code:
>  1. In org.apache.sshd.common.future.DefaultSshFuture#setValue:
> {code:java}
> public void setValue(Object newValue) {
>       // to simulate race condition
>       try {
>               Thread.sleep(10);
>       } catch (Exception e) {
>               // ignore
>       }
>         synchronized (lock) {
>             // Allow only once.
>             if (result != null) {
>                 return;
>             }
>             result = (newValue != null) ? newValue : GenericUtils.NULL;
>             lock.notifyAll();
>         }
>         notifyListeners();
>     }
> {code}
> 2. In org.apache.sshd.agent.local.AgentForwardedChannel#doWriteData:
> {code:java}
>  protected void doWriteData(byte[] data, int off, long len) throws 
> IOException {
>         ValidateUtils.checkTrue(len <= Integer.MAX_VALUE, "Data length 
> exceeds int boundaries: %d", len);
>         Buffer message = null;
>         synchronized (receiveBuffer) {
>             receiveBuffer.putBuffer(new ByteArrayBuffer(data, off, (int) 
> len));
>             // to simulate client disconnect suddenly
>             if (false && receiveBuffer.available() >= 4) {
>                 off = receiveBuffer.rpos();
>                 len = receiveBuffer.getInt();
>                 receiveBuffer.rpos(off);
>                 if (receiveBuffer.available() >= (4 + len)) {
>                     message = new ByteArrayBuffer(receiveBuffer.getBytes());
>                     receiveBuffer.compact();
>                 }
>             }
>         }
>         if (message != null) {
>             synchronized (messages) {
>                 messages.offer(message);
>                 messages.notifyAll();
>             }
>         }
>     }
> {code}
> After two munites, my console displayed 
> '[sshd-SshClient[720b3c53]-timer-thread-1] INFO 
> org.apache.sshd.client.session.ClientSessionImpl - 
> Disconnecting(ClientSessionImpl[root@/10.10.16.201:8022]): 
> SSH2_DISCONNECT_PROTOCOL_ERROR - Session has timed out waiting for 
> authentication after 120000 ms.' every second, and finally lead to 
> OutOfMemory Error.



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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to